Issue
I am getting the error:
'str' object has no attribute 'META'
The Traceback highlights this bit of code:
return render('login.html', c)
Where that bit of code is in my views.py:
from django.shortcuts import render
from django.http import HttpResponseRedirect # allows us to redirect the browser to a difference URL
from django.contrib import auth # checks username and password handles login and log outs
from django.core.context_processors import csrf # csrf - cross site request forgery.
def login(request):
c = {}
c.update(csrf(request))
return render('login.html', c)
This is what my template looks like:
{% extends "base.html"%}
{% block content %}
{% if form.errors %}
<p class = 'error'>Sorry, that's not a valid username or password</p>
{% endif %}
<form action = '/accounts/auth/' method = 'post'> {% csrf_token %}
<label for = 'username'>User name: </label>
<input type = 'text' name = 'username' value = '' id = 'username'>
<label for = 'password'>Password: </label>
<input type = 'password' name = 'password' value = '' id = 'password'>
<input type = 'submit' value = 'login'>
</form>
{% endblock %}
I assume I might be using render()
incorrectly but in the docs I think I am putting in the correct parameters.
https://docs.djangoproject.com/en/dev/topics/http/shortcuts/
Solution
First parameter to render()
is request
object, so update your line to
return render(request, 'login.html', c)
It is trying to refer request.META
, but you are passing 'login.html'
string, hence that error.
Answered By - Rohan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.