Django CMS pages throwing 404 for users who are not logged in to the admin

佐手、 提交于 2019-12-25 11:30:11

问题


All the pages throw a 404 error on a site for users who are not logged in. But if I log in to the admin and go back to view the site, all the pages are fine and viewable.

I've been using Django CMS for years and haven't come across this before. The only difference with this site is the default language is french, in my settings I have:

LANGUAGES = [
    ('fr', 'Francais'),
]

as my LANGUAGES setting and here is my LANGUAGE_CODE

LANGUAGE_CODE = 'fr' 

Here are my urls.py

from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings

admin.autodiscover()

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    url(r'^', include('cms.urls')),
)

if settings.DEBUG:
    urlpatterns = patterns('',
    url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
    url(r'', include('django.contrib.staticfiles.urls')),
) + urlpatterns

and my middleware...

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'cms.middleware.multilingual.MultilingualURLMiddleware',
    'cms.middleware.page.CurrentPageMiddleware',
    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.toolbar.ToolbarMiddleware',
)

What could be the cause of this?


回答1:


Just add a plus sign :)

if settings.DEBUG:
    urlpatterns += patterns('',



回答2:


I was in a similar situation to you: I'm using multiple languages with Django-CMS.

My issue was related to the CMS_LANGUAGES variable I'd defined: I'd simply lifted a portion of the example from the docs.

A comment on a GitHub issue helped point me in the correct direction.

I'd previously had the variable set up as:

CMS_LANGUAGES = {
    ...
    'default': {
        'fallbacks': ['en', 'de', 'fr'],
        'redirect_on_fallback': False,
        'public': False,
        'hide_untranslated': False,
    }
}

Notice the definition of the public boolean.

Also, make sure that you follow the instructions in the documentation with respect to setting up your language variables within the CMS_LANGUAGES dictionary.

Replacing the above with 'public': True got things working for me again.



来源:https://stackoverflow.com/questions/17148901/django-cms-pages-throwing-404-for-users-who-are-not-logged-in-to-the-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!