This article mainly introduces how to use the Python Django framework using an example of a voting program. Django is the most popular MVC Framework in the Python world. For more information, see
(1) about Django
(i) About Django
Django is a framework based on MVC constructs. But in Django, the part of the controller that accepts user input is handled by the framework itself, so Django is more concerned with models, templates, and views, called MTV mode.
Installation under Ubuntu: usually comes with
This article mainly introduces Django background custom form controls in Python. In fact, django has provided some available form controls for us, such as multiple selection boxes and single-choice buttons, if you are interested, start the business. This article mainly introduces Django background custom form controls
Use the example to explain how to optimize the database query by using the prefetch_related () function in the Django framework in Python, pythondjango
Instance background
Assume that the Personal Information System must record the home, residence, and city of each individual in the system. The database design is as follows:
The content of Models. py is as follo
This article mainly introduces the Django background custom form control in Python, in fact Django has provided us with some available form controls, such as: Multi-box, radio button, etc., interested in opening to understand.
In Django we can add in admin.py ModelAdmin , so that it is easy to do in the background o
. Import and Export data:Python manage.py dumpdata appname > appname.jsonpython manage.py loaddata Appname.json8.Django Project Terminal:Python manage.py ShellIf you installed the Bpython or Ipython will automatically use their interface, recommend the use of Bpython9. Database command line : ( inline SQLite)Python manage.py Dbshell10. More Commands:python manage.py # you can see a detailed list that is esp
This article mainly introduces the form processing example in the Python Django framework. form processing is a basic operation in Django. if you need it, you can refer to the following example about books, authors, and publishing houses:
from django.db import modelsclass
This article mainly introduces examples of Custom template tags in the Python Django framework. tags are more useful than filters. For more information about how to customize a template tag, see, you need to tell Django how to perform this process when encountering your tag.
When Django compiles a template, it divid
import render_to_responsedef search_form (Request): return Render_to_response (' Search_ Form.html ')
This view function can be placed anywhere in the Python search path. For the sake of discussion, let's put it in the books/views.py.
This search_form.html template may look like this:
Search
And the Urlpattern in urls.py may be this:
From mysite.books Import viewsurlpatterns = Patterns (", # ... (R ' ^search-form/$ ', views.search_form),
Python verification code based on Django (example), djangopython
Verification Code
On the user registration and logon page, you can add the verification code function to prevent brute-force requests. If the verification code is incorrect, you do not need to proceed with the verification code. This reduces the pressure on some servers.
Verification Code is also an
default content inherited from Base.html is displayed. {% Block content%}{% include'ad.html'%} #引用ad. html template. this isIndex page,welcome! {% Endblock%}Change the function that processes the request to return the template file to the client: (Of course, the content is rendered)In the app/views.py from Import def Home (Request): return'home.html' )Viii. Start-up project:[email protected] mysite]$Python manage.py runserver 0.0.0.0:8000Perform
This article mainly introduces the python send with pictures and attachments of the message, very practical value, the need for friends can refer to.
The group's SRC system needs to be done recently. No security research and development, so can only find me a part-time development of this dish. The system uses the Django framework, and there are many peculiar requirements throughout the process. In a deman
Simple python django framework development example, pythondjango
Create the views. py file in the/home/ubuntu/mysite directory as follows:
from django.http import HttpResponse,Http404import datetimeimport osdef sayhi(request): return HttpResponse('Hello World,this is my first Web page')
def current_time(request): ow = datetime.datetime.now() html
|Safe}}; //Remember to use safe to filter oh, otherwise you will get an error. //The following code puts each part of the list to the head and tail $('#list'). prepend (list[0]); $('#list'). Append (list[1]); Console.log ('---traverse List Method 1---'); for (varI=List.length- 1; I>= 0; I--){ //right mouse button, audit element, select Console to see the value enteredConsole.log (List[i]); }; Console.log ('---Traverse both the index and the content, using the
1. Install Pip
sudo apt-get install Python-pip
2. Install Django and create the project
Pip Install django==1.9.2django-admin.py Startproject MySite
CD MySite
3, Installation Python2.7-dev
sudo apt-get install Python2.7-dev
4, Installation Uwsig
sudo python2.7-m pip install Uwsgi
5. Then go to the directory to find the created project
Create test.py
corresponds to the field type in the database table, and the name can also be the same, it looks more intuitive. In this way, each class instance represents a piece of data in the database.
Model example (defined in models. py ):
from django.db import modelsclass Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField('date published')class Choice(models.Model): poll = models.ForeignKey(Poll)d choice_text =
campaign, more mature and lack of good programmers of the Python community has launched to contend with the Web development framework. After a comparison of the development framework of Python, I chose Python framework as the first choice of WEB development framework, the reason is that the new and concise Django deve
talented programmer, has launched a Web development framework to contend with in the face of Ruby on Rails's increasingly popular propaganda and fiery momentum. After comparing the development framework of Python, the author chooses the Python framework Django as the first choice of the Web development framework, and the reason is that the new and concise develo
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.