Anonymous user
Django for Designers/Basic views: Difference between revisions
→Handling URLs with templates
imported>Aldeka |
|||
(5 intermediate revisions by 3 users not shown) | |||
Line 2:
<!-- Instructor git note: You should do the above, and then do: git push origin HEAD:pre-part-2 -->
<div class="instructor">Time: 20 minutes</div>
=== Note for tutorial attendees ===
Line 23 ⟶ 25:
<div class="instructor">For Django, a ''model'' represents how the data is stored. This is the part of your app that ties your data to storage in a database. You write Python code, and Django converts it and out of into SQL, the language spoken by databases.
A ''view'' in Django handles a ''request'' from the website visitor for a web page. What you do with this request is up to you, and is the domain of the view code that you write. For example, when a request comes in, you could
The ''templates'' in Django control how data is presented. Typically, a view provides a collection of data to the template. The template then might loop over that information, wrap it in HTML bulleted lists, wrap ''that'' in a standard layout for all pages across your site, and serve that out to the site visitor. The templates usually refer to some ''static'' content, such as CSS, that makes the site actually seem designed!
Line 60 ⟶ 62:
</source>
Suppose a visitor to your site goes to (if you view the page, don't worry about the ViewDoesNotExist message, we'll get to that in a minute) [http://localhost:8000/tags/awesome/ http://localhost:8000/tags/awesome/].
* which regex pattern is tripped?
* what function is then called?
Line 190 ⟶ 192:
Now if you go to http://localhost:8000, you should see the webpage we made in our template file!
If you do not, you may need to '''restart your development server''' before it "sees" your template.
Save and commit your new template and template-based view.
Line 334 ⟶ 338:
Make sure you see ''manage.py'', and then let's continue.
Now let's add some more structure to our HTML templates to make them easier to style. First, base.html:
Line 435 ⟶ 437:
Save and commit your work!
[[Django_for_Designers/Adding_models|Next page]]
|