Home > other >  No response after click the submit, what reason be
No response after click the submit, what reason be

Time:10-12

 
The from the django. Shortcuts import HttpResponse

The from the django. Shortcuts import render

The from the django. Shortcuts import redirect

# the Create your views here.

Def index (request) :
Return an HttpResponse (" index ")

Def login (request) :
Print (" @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ ")
. If the request method=="GET" :
Print (" * * * * * * * * * * * * * * * * * * ")
Return render (request, "login. HTML")
# return redirect (request, "/index/")
Elif request. The method=="POST" :
V=request. POST. Get (" gender ")
F=request. POST. Getlist (" favor ")

Print (v)
Print (f)

The import OS
Obj=request. FILES. Get (" FFF ")
File_path=OS. Path. Join (" upload ", obj. Name)
F=open (file_path, mode="wb")
For I in obj. Chunks () :
F.w rite (I)
F. lose ()

Return render (request, "login. HTML")
# return redirect (request, "/index/")
The else:
Return redirect (request, "/index/")


Just started to learn, it made a login. The HTML,

Click on the submit, file upload, also have no reaction, what reason be?



<meta charset="utf-8" & gt;

<body>


Male: & lt; Input type="radio" name="gender" value="https://bbs.csdn.net/topics/1"/& gt;
Female: & lt; Input type="radio" name="gender" value="https://bbs.csdn.net/topics/2"/& gt;



Male: & lt; Input type="checkbox" name="favor" value="https://bbs.csdn.net/topics/11"/& gt;
Female: & lt; Input type="checkbox" name="favor" value="https://bbs.csdn.net/topics/22"/& gt;






CodePudding user response:

Your routing file, urls. Py
If routing write wrong

CodePudding user response:

The from the written form

CodePudding user response:

 
@ home. The route ('/login/', the methods=[' GET 'and' POST '])
Def the login () :
Form=LoginFrom ()
If the form. Validate_on_submit () :
Data=https://bbs.csdn.net/topics/form.data
User=user. Query. Filter_by (name=data [' name ']). The first ()
If not user. Check_pwd (data [' PWD ']) :
Flash (' password mistake, category='err')
Return redirect (url_for (' home. Login '))
The session [' login_user]=user. The name
Session. [' login_user_id]=user id
Userlog=userlog (
User_id=user id,
IP=request. Remote_addr
)
The db. The session. The add (userlog)
MIT ()
db.session.comReturn redirect (url_for (' home. User '))
Return render_template (' home/login. HTML, form=form)


 
The class LoginFrom (FlaskForm) :
"" "member login form "" "
Name=StringField (
Label='account',
Validators=[
DataRequired (' please enter account! ')
],
Description='account',
Render_kw={
'class' : "the form - the control input - lg",
"Placeholder" : "please enter the account,"
'required' : "required"
}
)

The PWD=PasswordField (
Label="password",
Validators=[
DataRequired (' please enter the password! ')
],
Description="password",
Render_kw={
'class' : "the form - the control input - lg",
"Placeholder" : "please enter the password",
'required' : "required",
'an autofocus' :' an autofocus'
}
)
Submit=SubmitField (
Label='login',
Render_kw={
'class' : "BTN BTN - lg BTN - success BTN - block"
}
)


 
.

{{form. The csrf_token}}
{{form. Submit}}


  • Related