【问题标题】:Django Python3 - AttributeError: 'module' object has no attribute 'META'Django Python3 - AttributeError:'module'对象没有属性'META'
【发布时间】:2016-03-15 20:17:21
【问题描述】:

运行时出现此错误...

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

这是我的 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>

这是form.py的内容...

from django import forms

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

这是我的看法……

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

    ticker(request)

最后是我的导入...

from .forms import EmailForm

有人知道为什么会这样吗?我对 Django 很陌生,需要一些帮助。

谢谢。

【问题讨论】:

    标签: python django python-3.x post django-forms


    【解决方案1】:

    你认为最后一行是什么?

    ticker(request)
    

    错误消息报告在对象中找不到“META”属性,AFAIK request 是 Django having an all-uppercase META attribute 中的唯一对象。所以我认为您只是通过传递不正确的HttpRequest object 来调用视图函数。

    你不应该直接调用你的视图,而是declare it in your URLconf 并从那里调用它。

    【讨论】:

      猜你喜欢
      • 2015-03-24
      • 2018-01-14
      • 2014-08-15
      • 1970-01-01
      • 2013-06-29
      • 2021-01-15
      • 2015-05-16
      • 1970-01-01
      • 2022-12-20
      相关资源
      最近更新 更多