django cmsplugin-blog无法正常工作

时间:2012-01-17 21:35:03

标签: django django-cms

我用django-cms安装了Django 1.3。一切正常。 之后我安装了cmsplugin-blog(来自djanog-cms网站的扩展页面),版本1.1.1

我似乎无法让我的网址正常工作。看起来博客应用程序正在生成正确的URL,但在打开帖子时,我收到404错误。我认为在博客应用程序的urls.py中可能存在错误:

from django.conf import settings
from django.conf.urls.defaults import *
from django.core.urlresolvers import reverse
from django.views.generic.date_based import archive_year, archive_month, archive_day, object_detail
from django.views.generic.list_detail import object_list

from tagging.views import tagged_object_list

from menus.utils import set_language_changer

from cms.models import Title
from cms.utils.urlutils import urljoin

from cmsplugin_blog.feeds import EntriesFeed, TaggedEntriesFeed, AuthorEntriesFeed
from cmsplugin_blog.models import Entry
from cmsplugin_blog.views import EntryDateDetailView, EntryArchiveIndexView

blog_info_dict = {
    'queryset': Entry.objects.all(),
    'date_field': 'pub_date',
    'allow_empty': True,
    'paginate_by': 15,
}

blog_info_tagged_dict = {
    'queryset_or_model': Entry.objects.all(),
    'allow_empty': True,
}

blog_info_author_dict = {
    'queryset': Entry.objects.all(),
    'allow_empty': True,
    'template_name': 'cmsplugin_blog/entry_author_list.html',
}

blog_info_month_dict = {
    'queryset': Entry.objects.all(),
    'date_field': 'pub_date',
    'month_format': '%m',
    'allow_empty': True,
}

blog_info_year_dict = {
    'queryset': Entry.objects.all(),
    'date_field': 'pub_date',
    'make_object_list': True,
    'allow_empty': True,
}

blog_info_detail_dict = dict(blog_info_month_dict, slug_field='entrytitle__slug')

def language_changer(lang):
    request = language_changer.request
    return request.get_full_path()

blog_archive_index = EntryArchiveIndexView.as_view()

def blog_archive_year(request, **kwargs):
    kwargs['queryset'] = kwargs['queryset'].published()
    set_language_changer(request, language_changer)
    return archive_year(request, **kwargs)

def blog_archive_month(request, **kwargs):
    kwargs['queryset'] = kwargs['queryset'].published()
    set_language_changer(request, language_changer)
    return archive_month(request, **kwargs)

def blog_archive_day(request, **kwargs):
    kwargs['queryset'] = kwargs['queryset'].published()
    set_language_changer(request, language_changer)
    return archive_day(request, **kwargs)

blog_detail = EntryDateDetailView.as_view()

def blog_archive_tagged(request, **kwargs):
    kwargs['queryset_or_model'] = kwargs['queryset_or_model'].published()
    set_language_changer(request, language_changer)
    return tagged_object_list(request, **kwargs)

def blog_archive_author(request, **kwargs):
    author = kwargs.pop('author')
    kwargs['queryset'] = kwargs['queryset'].published().filter(entrytitle__author__username=author)
    kwargs['extra_context'] = {
        'author': author,
    }
    set_language_changer(request, language_changer)
    return object_list(request, **kwargs)

urlpatterns = patterns('',
    (r'^$', blog_archive_index, blog_info_dict, 'blog_archive_index'),
    (r'^(?P<year>\d{4})/$', 
        blog_archive_year, blog_info_year_dict, 'blog_archive_year'),
    (r'^(?P<year>\d{4})/(?P<month>\d{2})/$', 
        blog_archive_month, blog_info_month_dict, 'blog_archive_month'),
    (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', 
        blog_archive_day, blog_info_month_dict, 'blog_archive_day'),
    (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', 
        blog_detail, blog_info_detail_dict, 'blog_detail'),
    (r'^tagged/(?P<tag>[^/]*)/$', blog_archive_tagged, blog_info_tagged_dict, 'blog_archive_tagged'),
    (r'^author/(?P<author>[^/]*)/$', blog_archive_author, blog_info_author_dict, 'blog_archive_author'),
    (r'^rss/any/tagged/(?P<tag>[^/]*)/$', TaggedEntriesFeed(), {'any_language': True}, 'blog_rss_any_tagged'),
    (r'^rss/tagged/(?P<tag>[^/]*)/$', TaggedEntriesFeed(), {}, 'blog_rss_tagged'),
    (r'^rss/any/author/(?P<author>[^/]*)/$', AuthorEntriesFeed(), {'any_language': True}, 'blog_rss_any_author'),
    (r'^rss/author/(?P<author>[^/]*)/$', AuthorEntriesFeed(), {}, 'blog_rss_author'),
    (r'^rss/any/$', EntriesFeed(), {'any_language': True}, 'blog_rss_any'),
    (r'^rss/$', EntriesFeed(), {}, 'blog_rss')      
)

任何帮助表示赞赏! 如果您需要更多配置,我可以发布它们。 感谢

settings.py

# -*- coding: utf-8 -*-
import os

gettext = lambda s: s

PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))



DEBUG = True
TEMPLATE_DEBUG = DEBUG


MANAGERS = ADMINS

DEFAULT_LANGUAGE = 0

DATABASES = {
    'default': {
        'ENGINE': '*******',
        'NAME': '*******',
        'USER': '*******',
        'PASSWORD': '*********',
        'HOST': '*******',
        'PORT': '*******',
    }
}

TIME_ZONE = 'Europe/Amsterdam'
LANGUAGE_CODE = 'nl'
SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True

# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True

MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')

# Make this unique, and don't share it with anybody.
SECRET_KEY = '**************************'

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

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.page.CurrentPageMiddleware',
    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.toolbar.ToolbarMiddleware',

    'cms.middleware.multilingual.MultilingualURLMiddleware', 
    'cmsplugin_blog.middleware.MultilingualBlogEntriesMiddleware',

    'debug_toolbar.middleware.DebugToolbarMiddleware',
)    

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.auth',
    'django.core.context_processors.i18n',
    'django.core.context_processors.request',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'cms.context_processors.media',
    'sekizai.context_processors.sekizai',
)

CMS_TEMPLATES = (
    ('base.html', 'Main Template'),
)

ROOT_URLCONF = 'urls'

TEMPLATE_DIRS = (
    os.path.join(PROJECT_DIR, 'templates'),
)

#for cms-blog
JQUERY_JS = 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js'
JQUERY_UI_JS = 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js'
JQUERY_UI_CSS = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/themes/smoothness/jquery-ui.css'

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'django.contrib.staticfiles',

    'debug_toolbar',

    'cms',
    'menus',
    'mptt',
    'south',
    'cms.plugins.text',
    'cms.plugins.picture',
    'cms.plugins.link',
    'cms.plugins.file',
    'cms.plugins.snippet',
    'cms.plugins.googlemap',
    'sekizai',

    'cmsplugin_contact',

    'cmsplugin_blog',
    'djangocms_utils',
    'simple_translation',
    'tagging',
    'staticfiles',
)

cms_app.py:

from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _

class BlogApphook(CMSApp):
    name = _("Blog Apphook")
    urls = ["cmsplugin_blog.urls"]

apphook_pool.register(BlogApphook)

2 个答案:

答案 0 :(得分:0)

您需要将博客应用的Apphook挂载到页面(请参阅http://readthedocs.org/docs/django-cms/en/latest/extending_cms/extending_examples.html#my-first-app-apphook)。

你需要为每种语言都这样做。

执行此操作后,您不得不重新启动服务器。

答案 1 :(得分:0)

没关系。我找到了解决方案...... 经过几个小时的调试后,我发现这毕竟是我的错误。我使用的是wsgi,apache.wsgi文件中的设置不正确。 在我的sys.path中,我还附加了另一个django项目的路径。由于这个追加是第一个,我的任何应用程序都无法读取正确的设置文件和url.py文件。

之后我花了一些时间搜索为什么百日草应用程序(我从cmsplugin-blog移动到百日草,它有更多的选项)不起作用。这篇文章帮助了正确的方向: http://groups.google.com/group/django-blog-zinnia/browse_thread/thread/4de2827343fb79e0

在我按正确的顺序放置我的网址模式后,一切正常!