gpt4 book ai didi

python - 使用 anchor 标记调用 View django

转载 作者:太空宇宙 更新时间:2023-11-04 15:02:13 25 4
gpt4 key购买 nike

项目.urls

from django.contrib import admin
from django.conf.urls import include, url, patterns
from django.conf.urls.static import static
from django.conf import settings
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
admin.autodiscover()

urlpatterns = patterns('',
url(r'^$', include('app.urls', namespace = 'app')),
)+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

urlpatterns += staticfiles_urlpatterns()

app.urls

urlpatterns = patterns('',
# ex: /polls/,
url(r'^', index.as_view(), name = 'index'),
url(r'^contact/', ContactMail.as_view(), name = 'contact'),
# url(r'^register/', register.as_view(), name = 'register'),
# url(r'^login/', login_user.as_view(), name = 'login'),

)+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

urlpatterns += staticfiles_urlpatterns()

html

<a class="page-scroll" href="{% url 'app:contact' %}">Contact</a>

我得到错误:

Reverse for 'contact' with arguments '()' and keyword arguments '{}' not found. 1 pattern(s) tried: [u'$contact/']

知道为什么会这样吗?

提前致谢!

最佳答案

您已通过以 $ 结尾的正则表达式包含应用程序网址,因此包含的任何内容都不会匹配。不要那样做。

url(r'^', include('app.urls', namespace = 'app')),

关于python - 使用 anchor 标记调用 View django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32703924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com