没有条目匹配查询 django

发布于 2024-12-11 22:26:55 字数 884 浏览 0 评论 0原文

好吧,我有一个非常奇怪的问题。我已经像这样映射了我的网址:

url(r'^contact/$', 'blog.views.contact'),

但是每当我转到/contact/时,我都会收到404,我已经多次检查了我的re,但无法弄清楚这里的问题是什么..

这是相关的联系人视图:

def contact(request):
    """
    """
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            send_mail("New contact form submission!", cd["message"],
                      "[email protected]", cd["email"])
            return redirect('blog.views.index')
    else:
        form = ContactForm()

    return render_to_response("contact.html", {"form" : form},
                              context_instance = RequestContext(request))

Okay so I've really weird problem. I've mapped my url like this :

url(r'^contact/

however whenever I go to /contact/, I get a 404, I've cheked my re several time and can't figure out what is the problem here..

Here's contact view if it's relevant :

def contact(request):
    """
    """
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            cd = form.cleaned_data
            send_mail("New contact form submission!", cd["message"],
                      "[email protected]", cd["email"])
            return redirect('blog.views.index')
    else:
        form = ContactForm()

    return render_to_response("contact.html", {"form" : form},
                              context_instance = RequestContext(request))
, 'blog.views.contact'),

however whenever I go to /contact/, I get a 404, I've cheked my re several time and can't figure out what is the problem here..

Here's contact view if it's relevant :

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尽揽少女心 2024-12-18 22:26:55

几种可能性:

1) 有问题的 URL 文件根本没有被包含在内。通过确认同一文件中的其他 URL 是否正常工作来测试这一点。

2) 另一种早期模式是匹配您的 URL,然后在视图中抛出 404。通过将此模式移至根 URL 中的第一个模式来测试这一点。

3)您的视图中的某些内容抛出了 404。根据您所包含的代码,这看起来不太可能,但可以通过用简单的东西(例如 direct_to_template)替换视图来测试这一点

A few possibilities:

1) The URLs file in question is not getting included at all. Test this by confirming that other URLs in the same file are working.

2) Another earlier pattern is matching your URL and then throwing a 404 in the view. Test this by moving this pattern to be the first pattern in your root URLs.

3) Something in your view is throwing the 404. This doesn't look likely, based on the code you've included, but test this by replacing the view with something simple, like a direct_to_template

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文