不显示表单数据在url django



我正在创建一个密码重置表单,用户经过身份验证后,他们可以在重置页面中输入用户名和新密码。但是,一旦他们设置了这个新数据并单击提交按钮,数据就会显示在所显示的下一页的url中。我需要如何配置我的应用程序以避免这样做?

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

{% 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 %}

这就是GET操作的工作方式。无论如何,您应该使用POST。

相关内容

  • 没有找到相关文章

最新更新