The first Django app we're going to make a polling site.He is made up of two parts:
A common interface allows users to vote
A management interface, to vote on the deletion.
First of all, you have to create a new project, just one line of code, and Django will automatically do the job for you.Switch the CD to the path you want to store your proje
Open the Current_datetime view. Here's what it says:
From django.http import httpresponseimport datetimedef current_datetime (Request): Now = Datetime.datetime.now () html = "It is now%s."% now return HttpResponse (HTML)
Let's use the Django templating system to modify the view. As a first step, you might have thought of making the following changes:
From django.template import template, Contextfrom django.http import httpresponseimport datetimed
To reduce the redundant code of the template loading call process and the template itself, Django provides a handy and powerful API for loading templates from diskTo use this template to load the API, you first have to tell the framework where to save the template.The saved file of the set is the settings.pymentioned in the previous section when we described the root_urlconf configuration.Installed_apps = (
In the previous sections we used a simple django.http.HttpResponse to display the content on the page, and this section explains how to use the render template to display the content.
Here I found an example of a summary of others. That's pretty detailed. The previous code and this section code are all based on Django 1.8, but Django 1.6,1.7 is also common, and the process is the same.
1. Create a Zqxt_
tornado_main.py ├──tornado_main.py~ └──ts ├──_ _init__.py ├──__init__.pyc ├──manage.py ├──settings.py ├──settings.py~ ├──settings.pyc ├──tornado_main.py ├──tornado_main.py~ ├──urls.py ├──urls.py~ ├──urls.pyc ├── views.py ├──views.pyc └──wsgi.pyQingming Festival ~ ~Chinese Traditional festivals, noon in dormitoryTomorrow will be class again, come on Oh!Reference Documentation:Official docum
RequirementsRequest. META is a Python dictionary that contains header information for all HTTP requests, such as the user's IP address and user agent. Through request. Meta.items () can get this dictionary. Requires meta information to be output to a Web page. Output resultsSource Codeindex.htmlviews.pyFrom django.shortcuts import render# Create your views here.def Display_meta (Request): values = Request. Meta.items () html = {} html[' index_title ']= ' Display META ' html[' index_
There are three ways to use the template Views From django.template Import loader, Context, templatefrom django.http import httpresponsefrom django.shortcuts Import renDer_tp_responsedef index1 (req): t = loader.get_template (' index.html ') c = Context ({' usename ': ' Jlan '}) returnHttpResponse (T.render (c)) def INDEX2 (req): t = tempate (' How to use Django templates
; P> inputtype= "Submit"value= "Submit"/> form>Body>HTML>test.htmldef Test (Request): if Request.method = = "GET": Return render (Request, ' Te St.html ') elif Request.method = = "POST": # text V = Request. Post.get (' pwd ') # Gets the input input box with the value print (v) # Radio V0 = Request. Post.get (' Gender ') # gets radio's value print (v0) # checkbox v1 = Request. Post.getlist (' favor ') # Gets the checkbox multiple selection in the case of value print (v1) # Select
:
3. Add our poll app to the admin management interface.
In the mysite/polls directory, create the admin. py file so that the content is as follows:
# Coding: cp936from mysite. Polls. Models import poll, choicefrom Django. contrib import adminadmin. Site. Register (poll) Admin. Site. Register (choice)
At this time, the corresponding poll and choice will appear in the admin Management Interface
In Django, files such as CSS and pictures need to be placed under the static file.Then create the following files in turn:Polls/static/polls/style.cssThen modify the Style.css as follows:Li a { color:green;}Next, add the following code to the polls/index.html:{% load staticfiles%} rel= "stylesheet" type= "text/css" href= "{% static" Polls/style.css '%} '/>EffectNext add a background image:Add the image background.gif under directory C:\mysi
As a little white with Python, starting to learn Django is doomed to a long way, documenting the learning process problems and solutions.Thanks to the selfless dedication of the "self-Improvement Academy", after installing Django 1.9.12 in the tutorial, try to create a new project with Python manage.py Startapp App-name has been unable to build the
The Django Admin site combined with ORM provides a very powerful database operation function, and a small amount of code can quickly realize the display, modification, saving of the database table data visualization pages and functions.The default display of the Django Admin page is divided into multiple app modules, and the database model defined below each
An excellent interface design, the most important two points should be the product itself UI and user experience (UX), only the perfect combination of the two can be called excellent design works. But with the development of smartphones and all kinds of design tools, the user's requirements for mobile interface design are increasing. This also explains why the mobile app market has a lot of app features, bu
Write the first Django app, the first part -- create a project
Let's use examples to learn.
Through this tutorial, we will teach you step by step to create a simple voting system.This system is divided into two parts:1. A public page allows people to vote and view the voting results.2. An administrator page allows you to add, modify, and delete votes.
Assume that you have installed
right corner of the Pycharm click Edit Configurations Editing configuration parameter points Open after the following dialog box, in scrip parametersIn the corresponding dialog box, enter the configuration parameters Runserver 0.0.0.0:8000. When the configuration is complete, click OK to finish.After configuring the above information, press CTRL+SHIFT+F10 to run the manage.py file: The following results appear D:\Python27\python.exe d:/djangotext01/manage.py runserver 0.0.0.0:8000Performing sys
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.