Some days ago, I saw a basic Python tutorial that was bought by Xiao Yang and created the idea of using Python to develop a small blog. This Python Web development series will not say much about Python's basic syntax, but is primarily practice-oriented. Using Python 2.7, the framework is
is that it does not run as a module within the same process as the Web server, but rather has its own independent process.
Why run code in a separate process?
In the traditional way of several mod_* embedded in the Apache script language (common example: Php,python/mod_python and Perl/mod_perl), They all embed themselves in the Apache process as an Apache extension module.
Each Apache process is a copy of
Context usage in Python's Django frameworkOnce you create a Template object, you can use the context to pass the data to it. A context is a collection of variables and their values.Context is represented in Django as the context class, in the Django.template module. Her constructor has an optional parameter: A dictionary-mapped variable and their value. Call the render () method of the template object and p
one, python InstallationUnder the Mac system, the system comes with the Python development environment, opens the terminal, enters the python, we can see the current Python version number, For example my system is OS X EI Caption 10.11.1, The
1. Python UpgradeBefore the Ubuntu comes with a lower version of Python, the following method can be done to upgrade.Use the command first: python-v to view the current Python version. Since 2.0 and 3.0 are syntactically different, upgrade to more than 3.0 here.# sudo apt-get update. % upgrade package; # sudo
Django's well-organized work behind the scenes. Don't worry if you don't understand what you have benefited from it. The only thing you need to know about Django's Unicode support will make it easy for your application to handle a wide variety of character sets, not just basic A-Z English characters.
Dictionary and Contexts
The dictionary data type of Python is a ing between keywords and their values. Context is similar to the dictionary. Context
Test.txt
Prod.txt
The remainder of this article describes how to migrate projects to this layout, and why this layout is better.Current default layout
We'll invoke the example Project Foo, and I know it's a very creative name. Let's assume here we're going to start foo.com. But when we want to map our project name to the final domain name, the project will exist here in a way that does not require any meaning.
If you use the
example, Installed_apps it from:
Installed_apps = (
...
..) )
To
Installed_apps = [
...
]
Now, based on specific profiles for each environment, we can more easily add and remove applications from foo/settings/base.py files. For example, you might want to install the Django Debugging toolbar only in the dev environment rather than in
environment (source env.rc). The script also sets the shortcut $mg for Python manage.py. You can invoke $mg in any directory to execute the Django command. For example, you use $MG runserver to start the test server.
The directory structure of the project corresponds to the following:
Note: There are too many files to remove some of the unimportant files
d
Serialization means that an object instance can be saved as a binary string. Of course, once saved as a binary string, it can also be saved as a text string. For example, if the value of a counter is 2, we can use the string "2. If there is an object called connter with the current value of 2, it can be serialized to "2", reverse, or a counter instance with the value of 2 can be obtained from "2. In this way, it will be serialized when it is shut down
This article mainly introduces some suggestions for deploying the Python Django framework, including the layout of project files, for more information, see "what is the optimal layout of Django applications, configuration files, and other related directories?"
Some friends always ask us this question, so I want to spend some time writing about how we really thin
Frameworkfor beginners, progressive is the most important, I recommend learning Flask (Welcome | Flask (A Python microframework) )Flask is so light that it can develop a simple website with very little cost. Very suitable for beginners to learn.Flask Framework Learning, you can consider the use of plug-ins. For example, use Wtform + flask-wtform to validate form data, and use SQLAlchemy + Flask-sqlalchemy
This article describes in detail how to simulate the Django framework in python and understand the basic functions required by a web framework. For more information, see
I. python web server implementation
Web development requires a web server first. For example, apache, but it is best to have a simple and convenient
This article mainly introduces the use of Context in the Python Django framework. rendering is the key to creating templates in Django. If you need a Template object, you can refer to this article, you can use context to pass data to it. A context is a collection of variables and their values.
Context is represented as the Context class in
After using Django for a long time, it is inevitable that the degree of freedom is insufficient. It is undeniable that the sacrifice of such degrees of freedom can bring some benefits. For example, an Integrated Framework (full-stack framework) can provide comprehensive solution. You do not need to worry about cache, session, feed, Orm, auth, template, and other problems, it can be used in full accordance w
First, understand the nature of Web applicationsFor all Web applications, essentially a socket server, the user's browser is actually a socket client.A simple web framework is implemented using the socket:#!/usr/bin/env python#Coding:utf-8 ImportSocketdefhandle_request (client): BUF= CLIENT.RECV (1024) Client.send ("http/1.1 ok\r\n\r\n") Client.send ("Hello, Seven.") defMain (): Sock=Socket.socket (socket.af_inet, socket. Sock_stream) Sock.bind (('loc
6: Admin.site.register (BookInfo, Bookinfoadmin)Or you can do it with an adorner, and write @admin.register (BookInfo) in front of the class.Set the admin site to display as Chinese and time zone (in setting.py) set to: Language_code= ' Zh-hans ' and time_zone= ' Asia/shanghai 'Set the inline class (or add the contents of the inline class when you add a table of data):For example: Class Neiqian (admin. Tabularinline):Model = Scord #对应要内嵌的数据库表Class St
Using Python's Django framework to generate PDF files,
The portable document format (PDF) is developed by Adobe and is mainly used to present printable documents, including pixel-perfect format, embedded fonts, and 2D vector images. You can think of a PDF document as the digital equivalent of a printed document; indeed, PDFs are often used in distributing parameters for the purpose of printing them.
It's easy to use
passed to the page ().Emptypage: When a valid value is provided to page (), but no object is thrown on that page. 2.Page Object :The page () method of the Paginator object returns the Page object and does not need to be built manually.Property: object_list: A list of all objects on the current page. Number: The ordinal of the current page, starting at 1. paginator: The Paginator object associated with the current Page object.Method: Has_next (): Returns True if there is a n
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.