Extracting something that is common to our code is a good programming habit. For example, two Python functions like the following:
def Say_hello (person_name): print ' Hello,%s '% person_namedef Say_goodbye (person_name): print ' Goodbye,%s '%
how the captured parameters work in conjunction with the include ()
A contained urlconf receives any captured parameters from the parent urlconfs, such as:
# root Urls.pyfrom django.conf.urls.defaults Import *urlpatterns = Patterns (', R ' ^ (? P
The common view method is to create a configuration dictionary in the urlconf file and then use those dictionaries as the third member of the urlconf tuple.
For example, here is a urlconf that renders a static "about" page:
From
The example in this article describes how Python reads Excel. Share to everyone for your reference. Specific as follows:
Today you need to take data from an Excel document (. xls) to a table in the database, starting with a line of lines. Later, I
In this paper, the method of calculating Pi pi by Python is described. Share to everyone for your reference. Specific as follows:
From sys import STDOUT scale = 10000 Maxarr = 2800 Arrinit = carry = 0 arr = [arrinit] * (Maxarr + 1) for I in xrange (
The examples in this paper describe the method of Python's basic binary transformation. Share to everyone for your reference. Specific as follows:
# parsing string with base into a number are easynum = Int (str, radix) # We have to write our own
The example in this article describes how Python simply calculates the folder size. Share to everyone for your reference. Specific as follows:
Import OS, re "" View all files and folders under the folder join is the concatenation function "" "Def
You will see a 404 error message if you want to see the site root directory through http://127.0.0.1:8000/. Django doesn't add anything to the site root, and in any case the URL is not special, just like the other entries in urlconf, it also relies
The example in this article describes how Python implements a batch of ways to turn word to HTML and publish HTML content to a Web site. Share to everyone for your reference. The implementation method is as follows:
#coding =utf-8__author__ = ' zhm
The examples in this article describe the characters that Python implements to find in the system disk. Share to everyone for your reference. Specific as follows:
"' Created on 2011-7-13@author:123 '" Import os# Save the current Disk Def existdisk (
As mentioned earlier in this chapter, a template filter is a simple way to modify the value of a variable before it is displayed. The filter uses the pipe character as follows:
{{Name|lower}}
The content that is displayed is the result of the
The key to traversing complex data structures in a Django template is the period character (.).
It is best to use a few examples to illustrate. For example, suppose you want to pass a Python dictionary to a template. To access the dictionary's
Method Invocation Behavior
Method invocations are slightly more complex than other types of lookups. Here are some things to note:
During a method lookup, if a method throws an exception, it is propagated unless the exception has a
One-time assignment to Current_datetime:
def current_datetime (Request): Now = Datetime.datetime.now () return Render_to_response (' Current_ Datetime.html ', {' current_date ': now})
Many times, as in this example, you find that you have
The Django templating system has never thought of implementing a fully functional programming language, so it does not allow us to execute Python statements in the template (or that sentence, see the concepts and Restrictions section for more
getting data from the request object
We've introduced the HttpRequest object in chapter Three when we're talking about the view function, but we didn't say much at the time. Let's recall that the first parameter of each view function is a
For example, you have a bunch of views that match a pattern, and a URL that doesn't match the pattern but the view logic is the same. In this case, you can forge the capture of the URL value by passing an extra urlconf parameter to the same
provides view configuration options
If you publish a Django app, your users may want to have some degree of freedom in their configuration. In this case, it would be a good idea to add some hooks to your view for the configuration options you think
The quickest way to modify the display of a form is to use CSS. In particular, the error list can enhance visual effects. An automatically generated list of errors using the exact '
", so that we can use CSS for them. The following CSS makes the
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