我遇到了这个错误:
"反向'创建'参数'()'和关键字参数' {}'未找到。尝试了1种模式:[u' $ create $']"
我无法看到问题所在。
日志是我的常规项目中的应用程序
这是我的Project / log / templates / log / index.html,其中包含我的表单:
<form action="{% url 'log:create' %}" method="post">
//...
</form>
这是Project / Project / urls / py:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^$', include('log.urls', namespace='log')),
url(r'^log/', include('log.urls', namespace='log')),
url(r'^admin/', include(admin.site.urls)),
]
这是我的Project / log / urls.py:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^login$', views.login, name='login'),
url(r'^logout$', views.logout, name='logout'),
url(r'^create$', views.create, name='create'),
]
然后我在Project / log / views.py中定义了我的函数create:
def create(request):
if request.method == "POST" and request.POST['name'] and request.POST['password']:
name_p = escape(request.POST['name'])
pass_p = escape(request.POST['password'])
try:
login = User.objects.get(username=name_p)
except:
user = User.objects.create_user(name_p, name_p+'@email.com', pass_p)
user.save()
return HttpResponseRedirect('log:index')
else:
return render(request, 'log/index.html', {'error_message' : 'The login you chose already exists',})
else:
return render(request, 'log/index.html', {'error_message' : 'You did\'t fill the entire form',})
我不知道我的错误在哪里,因为表单是一个简单的表单,没有传递参数,url中的正则表达式也是一个简单的表达式。我想我的功能一定是个问题。如果有人能引导我走上正确的道路来解决这种错误,那就太好了;)