Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Python-100-Days
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
huangkq
Python-100-Days
Commits
dd4e41fe
Commit
dd4e41fe
authored
Jul 05, 2018
by
jackfrued
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'更新了Django示例代码'
parent
267bd522
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
18 deletions
+34
-18
forms.py
Day41-55/code/hellodjango/demo/forms.py
+3
-3
views.py
Day41-55/code/hellodjango/demo/views.py
+8
-9
login.html
Day41-55/code/hellodjango/templates/demo/login.html
+5
-1
register.html
Day41-55/code/hellodjango/templates/demo/register.html
+18
-5
No files found.
Day41-55/code/hellodjango/demo/forms.py
View file @
dd4e41fe
...
...
@@ -4,9 +4,9 @@ from demo.models import User
class
UserForm
(
forms
.
ModelForm
):
username
=
forms
.
CharField
(
max_length
=
20
,
min_length
=
6
)
password
=
forms
.
CharField
(
widget
=
forms
.
PasswordInput
,
m
ax_length
=
20
,
min_length
=
8
)
email
=
forms
.
CharField
(
widget
=
forms
.
EmailInput
,
max_length
=
255
)
username
=
forms
.
CharField
(
widget
=
forms
.
TextInput
,
min_length
=
6
,
max_length
=
20
,
help_text
=
'请输入用户名'
)
password
=
forms
.
CharField
(
widget
=
forms
.
PasswordInput
,
m
in_length
=
8
,
max_length
=
20
,
help_text
=
'请输入密码'
)
email
=
forms
.
CharField
(
widget
=
forms
.
EmailInput
,
max_length
=
255
,
help_text
=
'请输入邮箱'
)
class
Meta
(
object
):
model
=
User
...
...
Day41-55/code/hellodjango/demo/views.py
View file @
dd4e41fe
...
...
@@ -27,22 +27,21 @@ def login(request):
def
register
(
request
):
form
=
UserForm
()
if
request
.
method
.
lower
()
==
'get'
:
return
render
(
request
,
'demo/register.html'
,
{
'f'
:
UserForm
()})
return
render
(
request
,
'demo/register.html'
,
{
'f'
:
form
})
else
:
ctx
=
{}
try
:
form
=
UserForm
(
request
.
POST
)
ctx
[
'f'
]
=
form
if
form
.
is_valid
():
form
.
save
(
commit
=
True
)
return
render
(
request
,
'demo/login.html'
,
{
'hint'
:
'注册成功请登录!'
})
else
:
return
render
(
request
,
'demo/register.html'
,
{
'hint'
:
'请输入有效的注册信息'
,
'f'
:
form
})
ctx
[
'hint'
]
=
'注册成功请登录!'
return
render
(
request
,
'demo/login.html'
,
ctx
)
except
:
return
render
(
request
,
'demo/register.html'
,
{
'hint'
:
'注册失败, 请尝试其他的用户名!'
}
)
ctx
[
'hint'
]
=
'注册失败, 请重新尝试!'
return
render
(
request
,
'demo/register.html'
,
ctx
)
def
show_subjects
(
request
):
...
...
Day41-55/code/hellodjango/templates/demo/login.html
View file @
dd4e41fe
...
...
@@ -11,13 +11,17 @@
#login
form
div
{
margin
:
10px
0
;
}
.hint
{
color
:
red
;
font-size
:
14px
;
}
</style>
</head>
<body>
<h1>
用户登录
</h1>
<hr>
<div
id=
"login"
>
<p
style=
"color: red; font-size: 12px;
"
>
{{ hint }}
</p>
<p
class=
"hint
"
>
{{ hint }}
</p>
<form
action=
"/login/"
method=
"post"
>
{% csrf_token %}
<div>
用户名:
</div>
...
...
Day41-55/code/hellodjango/templates/demo/register.html
View file @
dd4e41fe
...
...
@@ -4,33 +4,46 @@
<meta
charset=
"UTF-8"
>
<title>
用户注册
</title>
<style>
#
login
{
width
:
25
0px
;
#
reg
{
width
:
32
0px
;
margin
:
20px
auto
;
}
#
login
form
div
{
#
reg
form
div
{
margin
:
10px
0
;
}
.hint
{
color
:
red
;
font-size
:
14px
;
}
</style>
</head>
<body>
<h1>
用户注册
</h1>
<hr>
<div
id=
"
login
"
>
<p
style=
"color: red; font-size: 12px;
"
>
{{ hint }}
</p>
<div
id=
"
reg
"
>
<p
class=
"hint
"
>
{{ hint }}
</p>
<form
action=
"/register/"
method=
"post"
>
{% csrf_token %}
<div>
用户名:
</div>
<div>
{{ f.username }}
{% if f.errors.username %}
<span
class=
"hint"
>
用户已被注册
</span>
{% endif %}
</div>
<div>
密码:
</div>
<div>
{{ f.password }}
{% if f.errors.password %}
<span
class=
"hint"
>
无效的密码
</span>
{% endif %}
</div>
<div>
邮箱:
</div>
<div>
{{ f.email }}
{% if f.errors.email %}
<span
class=
"hint"
>
无效的邮箱
</span>
{% endif %}
</div>
<div>
<input
type=
"submit"
value=
"注册"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment