在urls.py里可以直接向函数传递默认值,看代码:
urls.py
from django.conf.urls import url
from mytest import views
urlpatterns = [
url(r'^index/', views.index, {'my': '呵呵'}),
]
views.py
from django.shortcuts import render
def index(req, my):
return render(req, 'index.html', {'data': my})
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index</title>
</head>
<body>
<h1>{{ data }}</h1>
</body>
</html>
看效果: