django cmsplugin-blog 不工作

发布于 2024-12-27 10:42:18 字数 7914 浏览 2 评论 0 原文

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

我似乎无法让我的网址正常工作。看起来博客应用程序正在生成正确的网址,但打开帖子时,我收到 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)

I've installed Django 1.3 with django-cms. All is working correctly.
After that I installed cmsplugin-blog (from the extensions page of the djanog-cms website), version 1.1.1

I can't seem to get my urls working correctly. It looks like the correct urls are being produced by the blog app, but when opening the posts, I get 404 error. I think it might be a mistake in the urls.py of the blog application:

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'^

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

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)
, blog_archive_index, blog_info_dict, 'blog_archive_index'), (r'^(?P<year>\d{4})/

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

settings.py


cms_app.py:


, 
        blog_archive_year, blog_info_year_dict, 'blog_archive_year'),
    (r'^(?P<year>\d{4})/(?P<month>\d{2})/

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

settings.py


cms_app.py:


, 
        blog_archive_month, blog_info_month_dict, 'blog_archive_month'),
    (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

settings.py


cms_app.py:


, 
        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]+)/

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

settings.py


cms_app.py:


, 
        blog_detail, blog_info_detail_dict, 'blog_detail'),
    (r'^tagged/(?P<tag>[^/]*)/

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

settings.py


cms_app.py:


, blog_archive_tagged, blog_info_tagged_dict, 'blog_archive_tagged'),
    (r'^author/(?P<author>[^/]*)/

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

settings.py


cms_app.py:


, blog_archive_author, blog_info_author_dict, 'blog_archive_author'),
    (r'^rss/any/tagged/(?P<tag>[^/]*)/

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

settings.py


cms_app.py:


, TaggedEntriesFeed(), {'any_language': True}, 'blog_rss_any_tagged'),
    (r'^rss/tagged/(?P<tag>[^/]*)/

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

settings.py


cms_app.py:


, TaggedEntriesFeed(), {}, 'blog_rss_tagged'),
    (r'^rss/any/author/(?P<author>[^/]*)/

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

settings.py


cms_app.py:


, AuthorEntriesFeed(), {'any_language': True}, 'blog_rss_any_author'),
    (r'^rss/author/(?P<author>[^/]*)/

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

settings.py


cms_app.py:


, AuthorEntriesFeed(), {}, 'blog_rss_author'),
    (r'^rss/any/

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

settings.py


cms_app.py:


, EntriesFeed(), {'any_language': True}, 'blog_rss_any'),
    (r'^rss/

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

settings.py


cms_app.py:


, EntriesFeed(), {}, 'blog_rss')      
)

Any help is appreciated!
If you need more configurations, I can post them.
Thanks

settings.py


cms_app.py:


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

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

发布评论

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

评论(2

颜漓半夏 2025-01-03 10:42:18

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

您需要对每种语言执行此操作。

不幸的是,完成此操作后,您必须重新启动服务器。

You need to mount the Apphook of the blog app to a page (see http://readthedocs.org/docs/django-cms/en/latest/extending_cms/extending_examples.html#my-first-app-apphook).

You need to do this for every language.

After you do that, you unfortunately have to restart the server.

怎樣才叫好 2025-01-03 10:42:18

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

之后,我花了一些时间寻找为什么 zinnia 应用程序(我从 cmsplugin-blog 转移到 zinnia,它有更多选项)无法工作。这篇文章朝着正确的方向提供了帮助:
http://groups.google.com/group/django-blog -zinnia/browse_thread/thread/4de2827343fb79e0

将网址模式按正确顺序排列后,一切正常 美好的!

Never mind. I've found the solution(s)....
After many hours of debugging I found out it was my mistake after all. I am using wsgi and the settings in the apache.wsgi file were incorrect.
In my sys.path I also appended a path from another django project. Since this append was the first one, it was never possible for any of my apps to read the correct settings files and url.py files.

After that it took me some time searching why the zinnia app (I moved from cmsplugin-blog to zinnia, which has much more options) wasn't working. This post helped in the right direction:
http://groups.google.com/group/django-blog-zinnia/browse_thread/thread/4de2827343fb79e0

After I put my url patterns in the correct order, everything worked fine!

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