Python新手使用的Django架站的16堂课 — 第八章
django-admin startproject ch08www
cd ch08www/
python manage.py startapp mysite
cd ch08www/
vi settings.py
<!-- index.html (ch08www project) -->
{% extends "base.html" %}
{% block title %}我有话要说{% endblock %}
{% block content %}
<div class='container'>
<form name='my form' action='/' method='GET'>
<label for='user_id'>Your ID:</label>
<input id='user_id' type='text' name='user_id'>
<label for='user_pass'>Your Password:</label>
<input id='user_pass' type='password' name='user_pass'>
<input type='submit' value='登录'>
<input type='reset' value='清除重填'>
</from>
</div>
{% endblock %}
ch08www / url.py
"""ch08www URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import include, url
from django.contrib import admin
from mysite import views
urlpatterns = [
url(r'^$', views.index),
url(r'^admin/', include(admin.site.urls)),
]
view.py
from django.shortcuts import render
# Create your views here.
from django.template.loader import get_template
from django.http import HttpResponse
from mysite import models
def index(request):
# products = models.Product.objects.all()
template = get_template('index.html')
html = template.render(locals())
return HttpResponse(html)
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver 192.168.99.218:8080
http://192.168.99.218:8080/admin
page 220
views.py
from django.shortcuts import render
# Create your views here.
from django.template.loader import get_template
from django.http import HttpResponse
from mysite import models
def index(request):
# products = models.Product.objects.all()
template = get_template('index.html')
try:
urid = request.GET['user_id']
urpass = request.GET['user_pass']
except:
urid = None
if urid != None and urpass == '12345':
verified = True
else:
verified = False
html = template.render(locals())
return HttpResponse(html)
index.html
<!-- index.html (ch08www project) -->
{% extends "base.html" %}
{% block title %}我有话要说{% endblock %}
{% block content %}
<div class='container'>
<form name='my form' action='/' method='GET'>
<label for='user_id'>Your ID:</label>
<input id='user_id' type='text' name='user_id'>
<label for_'user_pass'>Your Password:</label>
<input id='user_pass' type='password' name='user_pass'>
<input type='submit' value='登录'>
<input type='reset' value='清除重填'>
</from>
<br>Your ID:{{ urid | default:"未输入 ID"}}</br>
{% if verified %}
<em>您通过了验证</em>
{% else %}
<em>密码或账号打错了</em>
{% endif %}
</div>
{% endblock %}
显示效果:
page 222
这个没有搞出来
搜索 django checkbox
前端添加复选框checkbox 提交到django后台处理
https://www.cnblogs.com/dribs/p/6932353.html
(稍后补充)