Make a website with Django: Difference between revisions

imported>Jesstess
No edit summary
 
(21 intermediate revisions by 6 users not shown)
Line 1:
[[File:Django_pony.jpg|right|300px]]
 
== Project ==
 
Line 12 ⟶ 14:
==Project setup==
 
'''''Bold text''''Italic text'''''=== Install Django ===
 
Please follow the instructions in [https://docs.djangoproject.com/en/1.45/intro/install/ the official installation guide] to install Django.
 
=== Test your installation ===
Line 28 ⟶ 30:
 
The official Django tutorial walks you through creating an interactive polling application in 4 parts.
 
 
=== 1. Complete Part 1 of the tutorial ===
 
* Please visit https://docs.djangoproject.com/en/1.45/intro/tutorial01/ and complete part 1 of the tutorial.
 
In this part, you'll create a new project, learn how to run your development server, set up a database, and create some models for your polling app. Some of the setup that you are doing in this section will make more sense once you start actually using the code a bit later in the tutorial -- don't worry if the purpose of some of the steps you are going through is a bit unclear at first.
 
<br />
After you've completed part 1:<br />
<br />
<b>Check your understanding</b>: What is the relationship between the classes in <code>models.py</code> and the database schema displayed when you run <code>python manage.py sql polls</code>.
 
This tutorial covered a lot of ground quickly. If you have any questions or want to learn more, wave over a staff member!
 
 
=== 2. Complete Part 2 of the tutorial ===
 
* Please visit https://docs.djangoproject.com/en/1.45/intro/tutorial02/ and completedo almost all of part 2 of the tutorial. Stop when you get to the section "Customize the admin look and feel" (you can go back and read it later if you want, but it's not important for your first app).
 
<b>Check your understanding</b>: What does <code>api.GetSearch</code> return?
 
<br />
After you've completed part 2:<br />
<br />
<b>Check your understanding</b>: What did you have to do to get your poll app displayed on the admin index page?
 
=== 3. Complete Part 3 of the tutorial ===
 
* Please visit https://docs.djangoproject.com/en/1.45/intro/tutorial03/ and complete part 3 of the tutorial.
 
<br />
<b>Check your understanding</b>: What does <code>api.GetSearch</code> return?
After you've completed part 3:<br />
<br />
 
<b>Check your understanding</b>: What does <code>api.GetSearch</code> return?
 
<ol>
=== 4. Complete Part 4 of the tutorial ===
<li>
Which of the following URL fragments matches this pattern from a sample <code>urls.py</code>?
<pre>r'^polls/(?P<poll_id>\d+)/results/$'</pre>
 
* polls/ABC/results/
* Please visit https://docs.djangoproject.com/en/1.4/intro/tutorial04/ and complete part 4 of the tutorial.
* polls/12345/results/
* polls//results/
</li>
<li>
Why are templates a good idea?
</li>
<li>
What is the purpose of <code>template.render</code> in this code snippet?
 
<pre>def index(request):
<b>Check your understanding</b>: What does <code>api.GetSearch</code> return?
latest_poll_list = Poll.objects.order_by('-pub_date')[:5]
template = loader.get_template('polls/index.html')
context = Context({
'latest_poll_list': latest_poll_list,
})
return HttpResponse(template.render(context))</pre>
</li>
</ol>
 
=== 4. Complete Part 4 of the tutorial ===
 
* Please visit https://docs.djangoproject.com/en/1.45/intro/tutorial04/ and complete part 4 of the tutorial.
== Bonus exercises ==
 
If you have time, try out some of these extra exercises.
 
<br />
After you've completed part 4:<br />
<br />
 
===<b>Check 1.your Customizeunderstanding</b>: howWhat tweetsis are printed byin <code>searchrequest.POST</code> ===?
 
===Congratulations!===
The tweets printed by <code>search</code> could look much nicer and have more useful metadata!
 
You've built a website with Python and Django; this is a huge accomplishment. Keep practicing!
Customize how tweets are displayed. Look at the <code>Status</code> and <code>User</code> classes in http://code.google.com/p/python-twitter/source/browse/twitter.py for inspiration; options include displaying:
* the sender of the tweet
* the URL for the tweet
* how many followers the sender has
* the location of the sender
* if it was a retweet
 
[[File:Fireworks.png|150px]]
and more!
[[File:Balloons.png|150p
Anonymous user