我正在尝试使用包含3个选项的表单创建一个简单的网站,并在提交表单时显示一些显示所选选项的文本。
这是我到目前为止所拥有的......
的myapp /模板/ MyApp的/ index.html中:
<!DOCTYPE html>
<html>
<body>
<form method="get" action="{% url submit %}">
<input type="radio" name="which_choice" value="1">Choice 1<br>
<input type="radio" name="which_choice" value="2">Choice 2<br>
<input type="radio" name="which_choice" value="3">Choice 3<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
的myapp / views.py:
from django.shortcuts import render
def index(request):
return render(request, 'myapp/index.html')
def submit(request):
if 'which_choice' in request.GET:
message = 'The choice is: %r' % request.GET['which_choice']
else:
message = 'You submitted an empty form.'
return HttpResponse(message)
mysite的/ urls.py:
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^myapp/', include('myapp.urls')),
)
的myapp / urls.py:
from django.conf.urls import patterns, include, url
from myapp import views
urlpatterns = patterns('',
url(r'^index', views.index, name='index'),
url(r'^submit/$', views.submit, name='submit')
)
然而,当我从index.html页面提交按钮时,我收到“找不到页面/提交”404错误。我做错了什么?
感谢。