Alibabacloud.com offers a wide variety of articles about django url parameters in template, easily find your django url parameters in template information here online.
Catalogueone, Django URL Applicationsecond, Django View Applicationthird, Django Template ApplicationIv. Django's ORM ApplicationAdd:Supplement One: GetlisApplication Scenario: The current side of the data sent at multiple times, the background if you also get data with get,
If you want the form form to submit a URL that is similar to action= "/index-5-6.html", you can use the {% url ' test1 ' param1=5 param2=6%} in the HTML template language urls.pyFrom django.conf.urls import URL, includefrom mytest import viewsurlpatterns = [ url R ' ^inde
A. Regular URL (solves the problem that the regular part cannot be matched)-------xxx.html"/teacher_edit-{{Item.id}}"> Edit Url.pypath ('teacher_edit-(\d+)', Views.teacher_edit),--------views.pydefTeacher_edit (req): xxxx########################## #以上的正则url不能被识别, the workaround is as follows:----------------urls.py fromDjango.urlsImportPath,re_path#Introducing the Re_path moduleRe_path ('teacher_edit-(\d+)'
Templates href formathref= "{% url ' name ' params%}"Where: Name is the name alias that is configured for a URL in the url.py file, and each parameter specific value of the params URL is used as follows:Add a url,name parameter to the URL of the. py #在
The URL is like a tendon that connects the various parts of the Django framework tightly into a single whole, so it's a good idea to understand that Django starts from the URL.The relationship between the general view template URL is not covered here, and the following is a
URLs, like the collaterals, tightly link the various parts of Django's large framework into a single population, so it's a good idea to understand that Django starts from a URL.The relationship between the general view template URL is not discussed here, and the following is a sample of the passing of the parameters in
Static directory has CSS and JS and image folders, which put some static files of the site, static in the site root directory, Configuring static files in Django This is a matter of the Internet, and yesterday, when adding new content, found a problem, My URL If there are multiple "/" words (my is more than 3 such as:/A/B/C/D), the template calls to the static f
URL. Although this allows for the delivery of any number of parameters, but is not flexible enough, the URL seems to be confusing, and because it is a regular match, in some cases error prone.
4 through the traditional "?" Passing parameters
For example, in Http://127.0.0.1:8000/plist/?p1=chinap2=2012,
assigned according to the regular form of the URL. While this allows for the passing of any number of parameters, it is not flexible enough, the URL looks messy, and because it is a regular match, in some cases error prone.
4 through the traditional "?" Passing parameters
For example, in Http://127.0.0.1:8000/plist/
in the editing section, the idea is to jump to the page in the editor to give him a URL containing a unique ID, and then through the URL of the ID to query the data, the data content displayed on the edit page. 1. Edit button{{project.id}}'" >2.URL configuration, the part enclosed in () is the parameter, if there are multiple
('I am BeginMan! ')2 >>>response=HttpResponse('HelloWorld',mimetype='text/plain')
If you want to add content, you can use response as a class file object:
1 response=HttpResponse()2 response.write("
For more information, see the content in the Appendix of Django Book.
[2].In this (views. py) view, each function is called a view function. A view function uses an HttpRequest object as the first parameter, which is usually named request.
2.
parsingThe problem arises:As the function increases, there will be more views, perhaps the regular expression before the configuration is not accurate enough, so it is necessary to modify the regular expression, but once the regular expression has been modified, all the corresponding hyperlinks have to be modified, it is a troublesome thing, and may also miss some hyperlinks forget to modify, Is there a way to dynamically generate links based on regular expressions?Answer: Reverse parsing . Des
rendered data that is passed to the front end in the background, upper is the convert uppercase function View Code 3 custom functions for template invocation -Custom Template Filter A. Create folder in app Templatetags b. Create any py file, xx.py fromDjango Import Template Register=template. Library () @register. Fil
benefits are at the cost of brevity, and some developers believe that named group syntax is ugly and cumbersome.View functionsA view function, or briefly called a view, is a simple Python function that accepts a Web request and returns a Web response. The response can be the HTML content of a Web page, a redirect, a 404 error, an XML document, or a picture ... Is anything can. Returns a response regardless of the logic contained in the view itself.Render methodCombines a given
detail(request, question_id): question = get_object_or_404(Question, pk=question_id) return render(request, 'polls/detail.html', {'question': question})
The get_object_or_404 () function uses a Django model as its first parameter, and any number of keyword parameters as its second parameter, it will pass these keyword parameters to the get () function in t
. loader. get_template () function is used instead of manually loading the template from the file system. The get_template () function uses the Template Name as a parameter to locate the module location in the file system, open the file, and return a compiled Template object.The render (Context (locals () method receives a set of variable context. It returns a
fills the hole in the template to form a complete HTTP reply.As a little exercise in the content of the previous section, modify the west/urls.py yourself so that the Http://127.0.0.1:8000/west/templay URL request can find the corresponding View object.To access Http://127.0.0.1:8000/west/templay, you can see the page:2. ProcessLook at the whole process again. Templay () in west/views.py passes the environ
server-side navigation (redirection, etc.).There is a strong desire not to hardcode these URLs (laborious, non-extensible and prone to errors) or to design a specialized URL generation mechanism that is not related to urlconf, because it can easily lead to a certain amount of outdated URLs being generated.In other words, what is needed is a dry mechanism. In addition to the others, it also allows the design of URLs to be automatically updated without
How Django handles a requestWhen a user requests a page from the Django site, the following is the algorithm that the Django system decides which Python code to follow:1:django determines the root urlconf module to use. Typically, this value is the root_urlconf setting, but if the incoming HttpRequest object has a URLC
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.