The first experience of Django under Ubuntu (iii)--django experience

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.