简体   繁体   English

不显示网址Django中的表单数据

[英]Not show form data in url django

I am creating a password reset form after a user is authenticated they are presented with the reset page where they can enter the username and new password. 验证用户身份后,我将创建一个密码重设表单,并向他们显示重设页面,在这里可以输入用户名和新密码。 However once they have set this new data and click the submit button the data is shown in the url of the next page that is shown. 但是,一旦他们设置了新数据并单击Submit按钮,数据就会显示在下一页的url中。 How do I need to configure my application to not do this? 我该如何配置我的应用程序不执行此操作?

views.py views.py

def index(request):
if request.method == 'POST':
    form = login(request.POST)
    if form.is_valid():
        user = form.cleaned_data['username']
        passw = form.cleaned_data['password']
        if user and passw:
            #try the post to login
            r=validateUser(user,passw)
            if r:
                formReset = reset()
                return render(request, 'loggedin.html',{'form' : formReset})
            else:
                return render(request, 'index.html',{'form' : form})
else:
    form = login()
    loggedin(request)
    return render(request, 'index.html', {'form' : form})

def loggedin(request):
if request.method == 'GET':
    form = reset(request.GET)
    if form.is_valid():
        user = form.cleaned_data['username']
        newpassword = form.cleaned_data['newpassword']
        confirmnewpassword = form.cleaned_data['confirmnewpassword']
        if newpassword == confirmnewpassword:
            #passwords match
            val = resetpassword(user,newpassword)
        else:
            return render(request, 'loggedin.html', {"message" : 'Passwords do not match', 'form' : form})
else:
    return render(request, 'loggedin.html',{'form' : form})

forms.py 表格

from django import forms

class login(forms.Form):
#class used for the login prompt
username = forms.CharField(widget=forms.TextInput(attrs={'class' : 'btn btn-lg btn-default'}),label='')
password = forms.CharField(widget=forms.PasswordInput(attrs={'class' : 'btn btn-lg btn-default'}),label='')


class reset(forms.Form):
#class used for inputs to reset password
username = forms.CharField(widget=forms.TextInput(attrs={'class' : 'btn btn-default'}),label='User Name')
newpassword = forms.CharField(widget=forms.PasswordInput(attrs={'class' : 'btn btn-default'}),label='New Password')
confirmnewpassword = forms.CharField(widget=forms.PasswordInput(attrs={'class' : 'btn btn-default'}),label='Confirm Password')

loggedin.html loggingin.html

{% extends "base.html" %}
{% load staticfiles %}

{% block content %}
<form action="/" method="GET">
{% csrf_token %}
<div class="container">
    <h1>You are logged in</h1>
    {{ message }} </br>
    {{ form.as_p }}
    <input type="submit" class="btn btn-lg btn-default" action="submit" value="Reset">
</div></form>{% endblock %}

That's how a GET action works. 这就是GET操作的工作方式。 You should be using POST for this anyway. 无论如何,您应该使用POST。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM