After deploying the code UWSGI need to reboot, shut down the system firewall or open port
System version: CentOS7.0
Python version: Python3.6.3
Django Version: 2.0.5
Uwsgi version: 2.0.17
Nginx version 1.4.41. Install the required dependencies ' shellYum install wget openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
Yum Install libxml*Yum-y install gcc automake autoconf libtool make gcc-c+
Python network programming 08 ---- Django form, python08 ---- djangoI. retrieving data from the Request object we have already introduced the HttpRequest object when talking about the View function, but we didn't talk much about it at the time. Let us recall that the first parameter of each view function is an HttpRequest object, just like the following hello () function:
from django.http import HttpResponsedef hello(request): return HttpResponse("
Django entry record 2: django entry record
1. Create an app, python manage. py startapp appname
2. design the model and edit the model in the appname/directory.
3. Check the modification of the model. python manage. py makemigrations appname
4. automatically perform database migration and synchronize the database structure. python manage. py sqlmigrate 0001
5. Create a new data table named python manag
Let's look at how the serializer class can write the view function of the API, and now we won't use the attributes in the REST framework, just write the native Django view function.We create a subclass of HttpResponse to convert any data into JSON format.Editsnippets/views.py,如下:fromdjango.httpimporthttpresponsefromdjango.views.decorators.csrfimport Csrf_exemptfromrest_framework.renderersimportjsonrendererfromrest_framework.parsers importjsonparserfro
Use of the django master page, django
The master page is used to process the same part of the html page to avoid repeated
1. Add a master page
Add the templates folder in the same directory as the manage. py file to save the html file on the master page.
2、 basbase.html, html is as follows:
Use block for placeholder
3. Use the master page on a specific page
{% extends 'Base.html' %}{% block content%}This i
Deploy Django projects in BAE, and deploy django In bae
1. First create an application name on the BAE and purchase a space2. git the application folder to the local device. At this time, the folder will contain three more files: app. conf, favicon. ico, index. py.3. Create a local project: myblog in the application folder, and create a project app: blog in the local project.4. modify the content of the app
This should be the last learning module for Django. And then you need to go into the project to practice.
There are two ways to upload a Django file, one is the traditional IO-flow based operation, and one is encapsulated as an object-based operation.
But either way, you need to first create a directory of uploaded files,
Operation based on Io flow
The configuration in the URLs, based on the submission of
form, that is, set different types of input boxes#set name to text, cls_id as drop-down box classStudentform (Form): Name= fields. Charfield (widget=widgets. Inputtext ()) cls_id= fields. Integerfield (widget =widgets. Select ()) c. Set the contents of the drop-down box choices PropertiesclassStudentform (Form): cls_id=Fields . Integerfield (widget=widgets. Select (choices=models. Classes.objects.values_list ('ID','title')) Note: The value of choices must be a [tuple, (), ()] Type widget
the top layer of not, in the student table notinch(Learn the teacher course student's ID, as well as the group filter out duplicates) # First to find out what the teacher Li Ping taught lessons;--SelectStudent.sid,student.sname fromStudentwhereStudent.sid notinch (
--Selectstudent_id fromscore--wherescore.course_idinch(SelectCid fromCourse left join teacher on Course.teacher_id=teacher.tidwhereTeacher.tname='Mr. Li Ping')
--GROUP by student_id); # - whereGROUP BY has: Advanced
; TD>{{Item.age}}TD> TD>{{Item.email}}TD> TD>{{item.cls_id}}TD> TD> ahref= "/app01/edit_student/nid={{Item.id}}"class= "Glyphicon glyphicon-pencil">Edita>| ahref= "/app01/del_student/nid={{Item.id}}"class= "Glyphicon Glyphicon-trash">Deletea> TD>{#点击删除是一个get请求, to tell the server ID, you can get it through a URL get request, or a URL match to a pass to the
Document directory
CMS
Forum
Debugging
Database Upgrade
Unclassified
Looking for Django resources, the Wiki on the official website is also a good place.
Http://code.djangoproject.com/wiki/DjangoResourcesResources
Django Official Website
Django document
Django step by step was the best getting started tuto
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
Summary of Django middleware and summary of Django Middleware
I. Middleware
-- Middleware is a lightweight, underlying plug-in system that can be added to Django's request and response processes to modify Django's input and output.
-- Each middleware component is an independent Python class that can define one or more of the following methods
-- _ Init __: No parameter is required. The server calls the firs
Introduction to the web framework and django, and introduction to the web: django
All Web applications are essentially a socket server, and your browser is actually a socket Client.
Import socketdef f1 (request): "processes user requests and returns the following content: param request: all information of user requests: return: "f = open ('index. fsw ', 'rb') data = f. read () f. close () return data "" Sta
ORM database query operation API in the Django view, and django view ormapiAPIS for querying table records
Operation: models. Table name. objects. Method ()
All (): Query all results filter (** kwargs): it contains the object get (** kwargs) that matches the given filter condition ): returns an object that matches the given filtering condition. Only one of the returned results is returned. If more than one
Django uses multiple databases, while Django uses Databases
Some projects may involve the use of multiple databases. The method is simple.
1. Set the DATABASE in settings
For example, you need to use two databases:
DATABASES = { 'default': { 'NAME': 'app_data', 'ENGINE': 'django.db.backends.postgresql', 'USER': 'postgres_user', 'PASSWORD': 's3krit' }, 'users': { '
('%s? next=%s'% (settings. Login_url, Request.path)) Login_requierd ()Auth provides us with an adorner tool that is used to quickly add login checks to a view.Usage:Import login_required @login_requireddef My_view (Request): ... If the user is not logged in, it jumps to the Django default login URL '/accounts/login/' and passes the absolute path of the current access URL (redirected to the path after successful login).If you need to custo
A session is similar to an object in a dictionary and is readable and writable.It's a little different from cookies, and it's simple.I'll just say a little bit about the change here.1. Vim blog/views.pyIf Uf.is_valid ():Username = uf.cleaned_data[' username ']Password = uf.cleaned_data[' password ']Users = User.objects.filter (Username__exact=username,password__exact=password)req.session[' username ') = Username Direct transferIf users:Response = Httpresponseredirect ('/index/')Response.set_cook
Get and filter are different in Django's Orm.
The Django ORM framework is good for applications with low business complexity. It is easy to write and use. For beginners, the two longest-used get and filter methods in the query operation sometimes make some minor errors when you don't pay attention to them. The two methods in this section are different today.
I often use Django of version 1.5. Let's take
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.