wordpress 多站点 合集,贴吧广告投放,psd转wordpress,徐州建站模板语法及静态文件
1 多app创建 在主路由当中引入 include include()函数是Django.urls模块中的一个函数#xff0c;它的作用是在urls.py文件中引入其他应用的URL模式。 from django.urls import path, include创建多个app python manage.py startapp project_one
python ma…模板语法及静态文件
1 多app创建 在主路由当中引入 include include()函数是Django.urls模块中的一个函数它的作用是在urls.py文件中引入其他应用的URL模式。 from django.urls import path, include创建多个app python manage.py startapp project_one
python manage.py startapp project_two主路由添加两个app的路由 path(one/, include(project_one.urls))
path(two/, include(project_two.urls))对应子路由 # project_one
path(index/one/data/, views.index_one),
# 访问index_one视图路径one/index/one/data/# project_two
path(index/two/data/, views.index_two),
# 访问index_two视图路径two/index/two/data/2 模板语法
2.1 变量 变量的写法使用一个嵌套大括号{{ name }} def index_one(request):dict_data {}dict_data[name] 张三dict_data[love] [篮球, 羽毛球, 足球]return render(request, two/index_one.html, dict_data)/--index_one.html--?
h1大家好我是{{ name }}我喜欢{{ love.0 }}/h1
h1大家好我是{{ name }}我喜欢{{ love.1 }}/h12.2 标签 标签允许您执行以下操作如果条件for循环模板继承等。 for循环 def index_one(request):dict_data {}dict_data[love] [篮球, 羽毛球, 足球]return render(request, two/index_one.html, dict_data)/--index_one.html--?
{% for data in love %}h1{{ data }}/h1
{% endfor %}条件判断 def index_one(request):dict_data {}dict_data[age] 18return render(request, two/index_one.html, dict_data)/--index_one.html--?
{% if age 18 %}h1成年了/h1
{% else %}h1未成年/h1
{% endif %}3 表单提交
form methodpost{% csrf_token %}input typetext nameuser placeholder用户名input typepassword namepwd placeholder密码input typesubmit value提交
/form{% csrf_token %}是 Django 提供的防止伪装提交请求的功能。POST 方法提交的表格必须有此标签。
def login(request):if request.method GET:return render(request, two/login.html)else:username request.POST.get(user)password request.POST.get(pwd)print(username, password)if username admin and password 123456:# return HttpResponse(登录成功)# 重定向return redirect(/)else:return HttpResponse(登录失败)