Forms
Fun with Forms
Why use them?
1. Automatically generate form widgets.
2. Input validation.
3. Redisplay a form after invalid input.
4. Convert submitted form data to Python data types.
Fun with Forms
Example:
{{ poll.question }}
{% if error_message %}
{{ error_message }}
{% endif %}
Fun with Forms
Satisfying Sessions
You can uses sessions in Django, just like the
sessions in PHP
Sessions allow you to store state across different
pages of your website
Common uses: store logged in username, shopping
cart information, etc.
If you write to a session in one view (webpage), it
will be visible in all views afterwards as well
Session is found in the HttpResponse object
Real Live Examples!
Real-World Apps
MedSched
http://priyaram.scripts.mit.edu/practice/medsched/admin/
Shiny!
http://sjlevine.scripts.mit.edu/django/shiny/
Tutorial: Polling
Setting up Django through Scripts:
1. connect to athena:
>>ssh username@linerva.mit.edu
2. set up scripts
>>add scripts
>>scripts
3. Follow instructions from there to install Django
4. connect to scripts:
>>ssh scripts.mit.edu
>>cd ~/Scripts
From project folder run mysql
type “show databases;” to see your databases
type “use ;” to use a database
type “show tables;” to view the tables in that
database
type “drop table ;” to drop a table
Drop affected tables each time fields within your
models change.
Helpful Commands
Helpful Commands
>>./manage.py syncdb
or
>>python manage.py syncdb
Updates database tables whenever you drop
tables or add applications to INSTALLED_APPS in
settings.py
>>add scripts
>>foreachserver pkill u maria python
Restarts the development server to see your changes.
Handy References
Official Django website:
http://www.djangoproject.org/
Contains an amazing tutorial that you should follow
Information on setting up Django
Documentation for various classes, functions, etc.
Document Outline - Slide 1
- Slide 2
- Slide 3
- Slide 4
- Slide 5
- Slide 6
- Slide 7
- Slide 8
- Slide 9
- Slide 10
- Slide 11
- Slide 12
- Slide 13
- Slide 14
- Slide 15
- Slide 16
- Slide 17
- Slide 18
- Slide 19
- Slide 20
- Slide 21
- Slide 22
- Slide 23
- Slide 24
- Slide 25
- Slide 26
- Slide 27
- Slide 28
- Slide 29
- Slide 30
- Slide 31
- Slide 32
- Slide 33
- Slide 34
- Slide 35
- Slide 36
- Slide 37
- Slide 38
- Slide 39
- Slide 40
- Slide 41
- Slide 42
- Slide 43
- Slide 44
- Slide 45
- Slide 46
- Slide 47
- Slide 48
- Slide 49
- Slide 50
- Slide 51
- Slide 52
|