Code

Ticket #19582: proposal_0.rst

File proposal_0.rst, 1.6 KB (added by jpic, 17 months ago)

Proposal for tutorial06 about staticfiles: with smaller steps but not following the exact same pedagogy used to teach template file management

Writing your first Django app, part 6

This tutorial begins where :doc:`Tutorial 5 </intro/tutorial05>` left off. We've built a tested Web-poll application, and we'll now add some scripts and stylesheets.

?

Customize your app's look and feel

  • make polls/static/polls/style.css
  • load {% static 'polls/style.css' %} in polls/detail.html
  • realize that we want this stylesheet in all the templates
  • create 'polls/templates/polls/base.html',
  • load {% static 'polls/style.css' %} in polls/base.html
  • make all 3 polls templates to extend 'polls/base.html'

Customize your project's static files

  • create mysite/static
  • set STATICFILES_DIRS=[so.path.join(BASE_DIR, 'static')]
  • download jquery.js into mysite/static/jquery.js
  • make mysite/templates/base.html with {% static 'jquery.js' %}
  • make polls/base.html to extend mysite/base.html

Add a JavaScript script to your app's template

  • make polls/static/polls/vote.js
  • load {% static 'polls/vote.js' %} in polls/vote.html

What's next?

The beginner tutorial ends here for the time being. In the meantime, you might want to check out some pointers on :doc:`where to go from here </intro/whatsnext>`.

?

If you are familiar with Python packaging and interested in learning how to turn polls into a "reusable app", check out :doc:`Advanced tutorial: How to write reusable apps</intro/reusable-apps>`.

?