Pass extra parameters to the view function

stay urls.py Add the following to the file

from django.conf.urls import url
urlpatterns = [
url(r'index', views.index, {"name":'klvchen'}),
]

stay views.py Add the following to the file

def index(req, name):
return HttpResponse(name)

Defined name Variables can be directly in views.py Return in call

Django Of URL Alias

stay urls.py Add ,html Specify the path alias in klvchen that will do

urlpatterns = [
# ......
url(r"index", views.index, name="klvchen"),
]

stay templates Add a folder login.html file

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form ation={% url "klvchen" %} method="post">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="submit">
</form> </body>
</html>

stay views.py Add method

def index(req):
if req.method=="POST":
username = req.POST.get("username")
pwd = req.POST.get("password") print(username)
print(pwd) if username == "klvchen" and pwd=="123":
return HttpResponse(" Login successful ")
return render(req, "login.html")

Django Pass extra parameters and URL More articles about aliases

  1. pyqt Signals and slots transmit additional parameters

    Reprint :fengyu09 Environmental Science :python2.7.8 —— pyqt 4.11.1 Use Pyqt During programming , It is common to pass extra parameters to slot functions . But the signal - The slot mechanism just specifies how the signal is connected to the slot , Parameters of signal definition ...

  2. MVC Use Webuploader plug-in unit Passing extra parameters Take notes

    // Instantiation uploader = WebUploader.create({ pick: { id: '#filePicker-2', label: ' Click to select a picture ' }, formData: { k ...

  3. &lt; note &gt;TP5 Page passing extra parameters

    By default, only page One parameter , If you need to provide additional parameters to access paging ( For example, pagination of query results , You need to pass in the parameters of the query keyword to display the results ), You need to set additional parameters query

  4. Django( One ):url Routing configuration and template rendering

    urls.py Routing usage url Basic concepts url Format urls.py The role of url Analytic process include The role of kwarg The role of name The role of URL Concept URL(Uniform Resoure L ...

  5. Django--- Routing system ,URLconf Configuration of , Description of regular expressions ( Positional arguments ), Group naming ( Capture key parameters ), Pass extra parameters to the view , name url and url Reverse resolution of ,url The name space

    Django--- Routing system ,URLconf Configuration of , Description of regular expressions ( Positional arguments ), Group naming ( Capture key parameters ), Pass extra parameters to the view , name url and url Reverse resolution of ,url The name space I. 1 URLconf To configure ...

  6. Django Routing system based on Network :URL

    One . URLconf To configure The basic format from django.conf.urls import url urlpatterns = [ url( Regular expressions , views View , Parameters , Alias ), ] Parameter description ...

  7. django The routing system in (url)

    Routing system according to Django Appointment , One WSGI There are two core components in the application : Routing tables and views .Django frame The core function of is routing : according to HTTP In the request URL, Lookup routing table , take HTTP Request distribution to Different views to deal with ...

  8. django The passing of extra parameters and url name

    django Passing extra parameters path Method :path(route, view, kwargs=None, name=None) path Method can pass in a dictionary parameter with an extra parameter (kwarg), The values in the dictionary will ...

  9. django The corresponding relationship between road system and view ( The transmission of value )--&gt; primary coverage ( Positional arguments 、 Key parameters 、 Extra parameters 、include grouping [urls Distribution of ]、 Name groups 、 Reverse DNS 、APPEND_SLASH)

    The routing system is urls.py file , The view is views.py file Routing system inside to pay attention to urlpatterns The elements in () match the regular expression from top to bottom in writing order , Once the match is successful, it will not continue . If it is from UR ...

Random recommendation

  1. CGAffineTransformMakeRotation Achieve rotation

    UIImageView *image = [[UIImageView alloc]init]; image.frame = CGRectMake(50, 50, 200, 200); image.im ...

  2. Talk about jQuery The binding event

    http://www.jiangweishan.com/article/jQuery-bind-on.html $.extend({ hook:function(hookName){ var sele ...

  3. Linux The easiest way to change the host name

    I wrote an article about CentOS Changing the host name , It's complicated , See modifying alicloud for details CentOS Linux The hostname of the server . In today's askubuntu I found a very simple way to (How do I change the ...

  4. Macbo for Mac (10)- Switch multiple fragment

    ViewController.m #import "ViewController.h" #import "DJOneViewController.h" #imp ...

  5. ural 1286. Starship Travel

    1286. Starship Travel Time limit: 1.0 secondMemory limit: 64 MB It is well known that a starship equ ...

  6. linux Source code reading notes get_free_page() The code analysis

    /* 34 * Get physical address of first (actually last :-) free page, and mark it 35 * used. If no fre ...

  7. JS Choose OPTION

    var obj_prov = document.getElementById("prov"); var prov_text = obj_prov.options[obj_prov. ...

  8. elementary analysis busybox-1.12.0 in ash The limitations of script commands

    elementary analysis busybox-1.12.0 in ash The limitations of script commands LUTHER= It means that you will LUTHER Empty , Turn it into null echo ${LUTHER:-111} If before executing the sentence LUTHER Variable does not exist , So obvious ...

  9. 【 Baidu Maps API】 Establish a national bank location inquiry system ( Four )—— How to use Baidu map data to generate their own annotations

    original text :[ Baidu Maps API] Establish a national bank location inquiry system ( Four )-- How to use Baidu map data to generate their own annotations Abstract : Leave a suspense in the last chapter ," If you don't have a database of geographic coordinates , How to map the distribution of banks ?&quo ...

  10. [MNIST Data sets ] Preprocessing of input image

    because MNIST The data is 28*28 Black background and white image of , And you need to straighten it when you type it , That is to say, it can be seen as 1*784 The two-dimensional tensor of ( The value of the tensor is 0~1 Between ), So we need to preprocess the image , It's pictures that can be recognized by the Internet . Here's the code section i ...