python - Django login gives http 500 error -
so i'm making login system django application. works on dev side absolutely fine, in prod doesn't work if submit correct username , password (it gives 500 error). i'm not sure of 2 lines i've pointed out in views.py issue, figure must 1 of 2 since if enter incorrect user redirected fine, in prod.
the code on dev , prod side same - difference in settings
debug = true allowed_hosts = []
^ above dev settings, in prod debug false , allowed_hosts has been filled out appropriate names.
in views.py:
def user_login(request): if request.method == "post": username = request.post['username'] password = request.post['password'] user = authenticate(username=username, password=password) if user not none , user.is_active: login(request=request, user=user) <- line return render(request, 'site/homepage.html') <- or line else: return render(request, 'site/login.html', {'incorrect': true}) else: return render(request, 'site/login.html', {})
in login.html:
{% block content %} {% if user.is_authenticated %} <div class="title"> <h2>error</h2> </div> <p>you have logged in, {{ user.firstname }}. please logout login user!</p> {% else %} <div class="title"> <h2>login</h2> </div> {% if incorrect %} <p>you have entered wrong username and/or password.<br /> please try again</p> {% elif unauthorised %} <p>you must login before trying access page!<br /></p> {% endif %} <form id="login_form" method="post" action="#"> {% csrf_token %} <label>username: <input type="text" name="username" value="" size="50" /></label> <br /> <label>password: <input type="password" name="password" value="" size="50" /></label> <br /> <input type="submit" value="submit" /> </form> {% endif %} {% endblock %}
in form, action
attribute doesn't have value don't send view. should "."
<form id="login_form" method="post" action=".">
or
<form id="login_form" action="{% url 'login' %}" method="post">
if login url name login
.
Comments
Post a Comment