【问题标题】:How come I can't include other URLs.py into my Django?为什么我不能将其他 URLs.py 包含到我的 Django 中?
【发布时间】:2011-01-08 01:58:21
【问题描述】:

我有一个 urls.py。其中一位说这行:

(r'^notification/?$',include("notification.urls")),

我应该这样做,因为我在 INSTALLED_APPs 中安装了“django_notification”(并添加了“通知”)。

太棒了!去 /notification/ 工作!这是通知模块中的urls.py:

from django.conf.urls.defaults import *

from notification.views import notices, mark_all_seen, feed_for_user, single, notice_settings

urlpatterns = patterns('',
    url(r'^$', notices, name="notification_notices"),
    url(r'^settings/$', notice_settings, name="notification_notice_settings"),
    url(r'^(\d+)/$', single, name="notification_notice"),
    url(r'^feed/$', feed_for_user, name="notification_feed_for_user"),
    url(r'^mark_all_seen/$', mark_all_seen, name="notification_mark_all_seen"),
)

但是,只有 /notification 有效,当我点击该网址时,它会显示“通知”一词。没有其他工作。 /设置,/饲料。这些都不起作用。我收到一个 404 错误,Django 按顺序尝试了所有 URL。

也许是因为“notification_notice”这件事??

【问题讨论】:

    标签: python django templates url notifications


    【解决方案1】:

    如果您阅读文档,您会看到包含将删除匹配的部分,因此您必须转到 /notification/settings 和 /notification/feed

    【讨论】:

    • 是的,我去 mydomain.com/notifications/ettings 。但这不起作用。但是,我在我的网址中尝试了各种各样的东西,但它不起作用。
    • @TIMEX:“它不起作用”含糊不清,难以解释。您能否更准确地说明哪些有效,哪些无效?
    【解决方案2】:

    解决了。

    我删除了网址匹配末尾的?$。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-05
      • 2014-06-17
      • 1970-01-01
      • 2010-11-01
      • 2016-11-17
      • 1970-01-01
      相关资源
      最近更新 更多