Important Concepts in Django:
The essence of a Web visit:
1. The client sends an HTTP request to the Web service back
2. The Web server returns an HTML page to the customer
Django Overview:
1. URL configuration establishes the URL and the relationship to the response function
2. View views respond to customer HTTP requests, logical processing, return to the user HTML page
3. Model models describes the data stored by our server (table of the database)
4. Template templates is used to produce HTML pages. The HTML returned to the user is rendered by the data (model) and template.
Blog Example:
To edit mysite/urls.py, add the following code:
URL (r'^$'blog.views.showBlogList'), URL (r ' ^blog/(\d+) $ ' ' blog.views.showBlogList '),
Add in blog/views.py:
From django.shortcuts Import Render
From django.http import HttpResponse, Httpresponsenotfound, Httpresponseredirect, Jsonresponse, FileResponse
From django.template Import Loader
From. Models Import Blog
#Create your views here.defShowblog (Request, blogId): t= Loader.get_template ('blog.html') Blog= Blog.objects.get (id=blogId) Context= {'Blog': Blog} HTML=T.render (context)returnHttpResponse (HTML)defshowbloglist (Request): T= Loader.get_template ('blog_list.html') Blogs=Blog.objects.all () context= {'Blogs': Blogs} HTML=T.render (context)returnHttpResponse (HTML)
The first experience of Django under Ubuntu (iii)--django experience