Python 视图中窗体中的Django文档错误:AttributeError:module';mdntuto.views';没有属性';你好';

Python 视图中窗体中的Django文档错误:AttributeError:module';mdntuto.views';没有属性';你好';,python,django,Python,Django,我已经阅读了3.2.2版Django文档的完整表格,现在我正在研究表格文档中提供的实用表格和面对面属性错误: 代码是从Django文档复制的。仍然会留下一个错误。我检查了4次没有发现错误 错误是: path('hello/', views.hello, name='hello'), AttributeError: module 'mdntuto.views' has no attribute 'hello' 代码如下 forms.py from django import forms cl

我已经阅读了3.2.2版Django文档的完整表格,现在我正在研究表格文档中提供的实用表格和面对面属性错误: 代码是从Django文档复制的。仍然会留下一个错误。我检查了4次没有发现错误

错误是:

path('hello/', views.hello, name='hello'),
AttributeError: module 'mdntuto.views' has no attribute 'hello'
代码如下

forms.py
from django import forms


class NameForm(forms.Form):
    your_name = forms.CharField(label='Your name', max_length=100)
    user_name = forms.CharField(label='Last name', max_length=20, required=True)
    mobile_number = forms.IntegerField(label='Contact No.')
    email = forms.EmailField(label='Email Address', initial='foo@foo.com', required=True)
    date_of_birth = forms.DateField(label='Enter DOB', initial='YYYY-MM-DD format')
hello.html
{%csrf_令牌%}
{{form.as_p}}

查看函数的名称必须与
url.py中的函数名称匹配。您需要将
url.py
更改为
path('hello/',views.get_hello,name='hello')
,或者将视图函数更改回
def hello(请求):
@everyvan谢谢
views.py
from django.http import HttpResponseRedirect
from .forms import NameForm
from django.http import HttpResponse
from django.shortcuts import render

def get_hello(request): 
# if use def hello(request): it works fine
# def get_hello(request) is as per Django Docs.
    if request.method == 'POST':
        form = NameForm(request.POST)
        if form.is_valid():
            return HttpResponseRedirect('/thanks/')
    else:
        form = NameForm()
    return render (request, 'mdntuto/hello.html', {'form': form})
hello.html
<form action="/your-name/" method="POST">
    {% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Submit">
</form>