Django for ISchoolers: Difference between revisions

no edit summary
imported>Aldeka
No edit summary
imported>Aldeka
No edit summary
Line 256:
== Starting yer app ==
 
In this tutorial, we’ll create our pollQ&A app in the myproject directory for simplicity. In the future, when you decide that the world needs to be able to use your pollQ&A app and plug it into their own projects, and after you determine that your app plays nicely with other apps, you can publish that directory separately!
 
* Open your terminal and navigate into the mysite folder
Line 365:
* Save and commit.
 
Review: When somebody requests a page from your Web site – say, “/questions/23/”, Django will load the urls.py Python module, because it’s pointed to by the ROOT_URLCONF setting. It finds the variable named urlpatterns and traverses the regular expressions in order. When it finds a regular expression that matches – r'^pollsquestions/(\d+)/$' – it loads the function question() from qandabear/views.py. Finally, it calls that module’s detail() function like so:
 
<code>detail(request=<HttpRequest object>, '23')</code>
Line 380:
* Fetch “http://127.0.0.1:8000/questions/” in your browser. You should get a pleasantly-colored error page with the following message:
 
<code>ViewDoesNotExist at /pollsquestions/
 
Tried index in module qandabear.views. Error was: 'module'
Line 399:
'/Users/adalovelace/gits/mysite/questions/views.py'</code>
 
So, a mystery? Where is the view!? It’s nowhere! The URL parsing is going fine, but there is no one listening at the other end of the phone! This ViewDoesNotExist error happened because you haven’t written a function index() in the module pollsquestions/views.py.
 
Well, I guess we should do that!
Line 571:
===Fix The Hideous Default Representation===
 
Wait a minute! <Question: Question object> is an utterly unhelpful, truly wretched, beyond contemptable representation of this object. Let’s fix that by editing the Question model. Use your text editor to open the pollsqandabear/models.py file and adding a __unicode__() method to both Question and Answer:
 
<code>class Question(models.Model):
Anonymous user