Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'str' object has no attribute 'META'

Tags:

python

django

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/

like image 652
Liondancer Avatar asked Nov 18 '13 10:11

Liondancer


1 Answers

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.

like image 57
Rohan Avatar answered Oct 10 '22 07:10

Rohan