Django Python3 - AttributeError:'module'对象没有属性'META'

时间:2021-07-24 18:18:34

This error is occurring whilst being run...

运行时发生此错误...

AttributeError: 'module' object has no attribute 'META'

Here is my html form...

这是我的html表单......

    <form method="POST" action="">
    {% csrf_token %}
    <label for="ticker">Ticker: </label>
    <input type="text" name="ticker"/>
    {{ form.as_p }}
    <input type="submit" value="Submit" class="btn" />
    </form>

Here is the contents of form.py...

这是form.py的内容......

from django import forms

class EmailForm(forms.Form):
    email = forms.TextInput()

And here is my view...

这是我的看法......

    def ticker(request):
        form = EmailForm()
        context = {"form": form}
        template = "stocks.html"
        return render(request, template, context)

    ticker(request)

And finally my import...

最后我的导入......

from .forms import EmailForm

Does anyone know why this is happening? I'm very new to Django and need some help.

有谁知道为什么会这样?我对Django很新,需要一些帮助。

Thanks.

1 个解决方案

#1


0  

What is this last line in your view?

您认为最后一行是什么?

ticker(request)

The error message is reporting that the "META" attribute is not found in an object, and AFAIK request is the only object in Django having an all-uppercase META attribute. So I think you're simply calling the view function by passing something that isn't a proper HttpRequest object.

错误消息报告在对象中找不到“META”属性,并且AFAIK请求是Django中具有全大写META属性的唯一对象。所以我认为你只是通过传递一个不是正确的HttpRequest对象的东西来调用view函数。

You're not supposed to call your view directly, but rather declare it in your URLconf and have it called from there.

你不应该直接调用你的视图,而是在你的URLconf中声明它并从那里调用它。

#1


0  

What is this last line in your view?

您认为最后一行是什么?

ticker(request)

The error message is reporting that the "META" attribute is not found in an object, and AFAIK request is the only object in Django having an all-uppercase META attribute. So I think you're simply calling the view function by passing something that isn't a proper HttpRequest object.

错误消息报告在对象中找不到“META”属性,并且AFAIK请求是Django中具有全大写META属性的唯一对象。所以我认为你只是通过传递一个不是正确的HttpRequest对象的东西来调用view函数。

You're not supposed to call your view directly, but rather declare it in your URLconf and have it called from there.

你不应该直接调用你的视图,而是在你的URLconf中声明它并从那里调用它。