【问题标题】:Django Admin Urls Not WorkingDjango 管理 URL 不起作用
【发布时间】:2013-12-11 04:19:20
【问题描述】:

我的一些 django url 不起作用。我可以访问我的索引页面和 django 管理页面就好了。我可以登录并创建对象没问题。例如,我可以创建一个站点,如下所示,但是当我尝试访问站点集合时,我会遇到 404(即使在创建一个之后)。我也在使用 Django allauth,这些页面也遇到了我的 urlconf 的问题。谁能发现错误?

比如这个网址:

Page not found (404)
Request Method:     GET
Request URL:    http://myapp.com/admin/sites/site/

No reward found matching the query

还有这个:

Page not found (404)
Request Method:     GET
Request URL:    http://shielded-island-1440.herokuapp.com/accounts/profile/

Using the URLconf defined in litherewards.urls, Django tried these URL patterns, in this order:

^ ^$ [name='index']
....
^ ^reward/$ [name='reward_list']
^ ^redeem/(?P<reward_code>)/$ [name='redeem_reward']
^ ^redeem/(?P<slug>\w+)/(?P<reward_code>\w+)/$ [name='reward_confirmation']
....
^account/
^sitemap\.xml$
^admin/

我的urlconf如下:

from django.conf.urls import patterns, include, url
from myapp.views import RewardSitemap

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
admin.autodiscover()

sitemaps = {'rewards':RewardSitemap}
urlpatterns = patterns('',
    url('^', include('myapp.urls', namespace="fluffy")),
    url(r'^account/', include('allauth.urls')),
    url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),
    url(r'^admin/', include(admin.site.urls)),
)

第一个urlconf中包含的myapp url:

urlpatterns = patterns('',
    url(r'^$', IndexView.as_view(), name="index"),
    ....
    url(r'^reward/$', RewardsList.as_view(), name="reward_list"),
    url(r'^redeem/(?P<reward_code>)/$', RedeemReward.as_view(), name="redeem_reward"),
    url(r'^redeem/(?P<slug>\w+)/(?P<reward_code>\w+)/$', RedeemConfirmation.as_view(), name="reward_confirmation"),
)

最后,我的ROOT_URLCONF 设置为myapp.urls。索引页工作正常。

【问题讨论】:

  • 对于第二种情况,uri 应该是 /account/profile 而不是 /accounts/profile no - 's',或者将 urls.py 更改为具有模式 ^accounts/
  • 通过将 admin 的 url 首先放在顶部来更改顺序
  • 您是否为管理员使用自定义模板?该错误与您的 redeem_reward 视图有关,该视图在某处被调用。您应该发布完整的回溯。

标签: python django admin urlconf


【解决方案1】:

根据我所拥有的有限知识,我看到 URl 模式具有“account/”,并且您正在访问“http://shielded-island-1440.herokuapp.com/accounts/profile/”,这与您的 URLConf 中的任何正则表达式模式都不匹配。

您可以尝试修改为 url(r'^accounts/', include('allauth.urls')), 吗?

【讨论】:

    猜你喜欢
    • 2023-04-05
    • 2013-06-07
    • 2015-11-18
    • 2023-04-06
    • 2017-02-19
    • 1970-01-01
    • 2013-05-04
    • 2012-08-01
    • 2015-10-06
    相关资源
    最近更新 更多