简体   繁体   English

如何安装Mezzanine作为Django应用程序?

[英]How do I install Mezzanine as a Django app?

I already have an existing Django website. 我已经有了一个现有的Django网站。 I have added a new url route '/blog/' where I would like to have a Mezzanine blog. 我添加了一个新的网址'/ blog /',我希望有一个Mezzanine博客。 If it possible to installed Mezzanine as an app in an existing Django site as opposed to a standalone blog application. 如果可以将Mezzanine安装为现有Django站点中的应用程序而不是独立的博客应用程序。

If you are like me, you will find that the FAQ is sorely lacking in its description of how to get Mezzanine working as an app. 如果你像我一样,你会发现常见问题解答中非常缺乏如何让Mezzanine作为应用程序工作的描述。 So here is what I did (after a painful half day of hacking) to get it integrated (somewhat): 所以这就是我所做的(在一次痛苦的半天黑客攻击之后)将其整合(有点):

  1. Download the repo and copy it into your project 下载仓库并将其复制到您的项目中
  2. Run setup.py for the package 运行包的setup.py
  3. cd to the package and run the mezzanine command to create a new app ( mezzanine-project <project name> ), let's say you use the name blog as your <project_name> . cd到包并运行mezzanine命令来创建一个新的应用程序( mezzanine-project <project name> ),假设您使用名称blog作为<project_name>
  4. In either the local_settings.py or settings.py file, set the DATABASES dict to use your project's database. local_settings.pysettings.py文件中,将DATABASES dict设置为使用项目的数据库。
  5. Run the createdb command from the mezzanine manage.py file 从夹层manage.py文件中运行createdb命令

Now it's time to start the hack-fest: 现在是时候开始hack-fest了:

  1. In your project's settings.py file, add blog to INSTALLED_APPS 在项目的settings.py文件中,将blog添加到INSTALLED_APPS
  2. Add some configuration variables to settings.py that Mezzanine is expecting: PACKAGE_NAME_FILEBROWSER = "filebrowser_safe" PACKAGE_NAME_GRAPPELLI = "grappelli_safe" GRAPPELLI_INSTALLED = False ADMIN_REMOVAL = [] RATINGS_RANGE = range(1, 5) TESTING = False BLOG_SLUG = '' COMMENTS_UNAPPROVED_VISIBLE = True COMMENTS_REMOVED_VISIBLE = False COMMENTS_DEFAULT_APPROVED = True COMMENTS_NOTIFICATION_EMAILS = ",".join(ALL_EMAILS) COMMENT_FILTER = None 将一些配置变量添加到Mezzanine期望的settings.py中: PACKAGE_NAME_FILEBROWSER = "filebrowser_safe" PACKAGE_NAME_GRAPPELLI = "grappelli_safe" GRAPPELLI_INSTALLED = False ADMIN_REMOVAL = [] RATINGS_RANGE = range(1, 5) TESTING = False BLOG_SLUG = '' COMMENTS_UNAPPROVED_VISIBLE = True COMMENTS_REMOVED_VISIBLE = False COMMENTS_DEFAULT_APPROVED = True COMMENTS_NOTIFICATION_EMAILS = ",".join(ALL_EMAILS) COMMENT_FILTER = None
  3. Add some middleware that Mezzanine is expecting: ```` ... "mezzanine.core.request.CurrentRequestMiddleware", "mezzanine.core.middleware.RedirectFallbackMiddleware", "mezzanine.core.middleware.TemplateForDeviceMiddleware", "mezzanine.core.middleware.TemplateForHostMiddleware", "mezzanine.core.middleware.AdminLoginInterfaceSelectorMiddleware", "mezzanine.core.middleware.SitePermissionMiddleware", 添加Mezzanine期待的一些中间件:````mezzanine.core.request.CurrentRequestMiddleware“,”mezzanine.core.middleware.RedirectFallbackMiddleware“,”mezzanine.core.middleware.TemplateForDeviceMiddleware“,”mezzanine.core。 middleware.TemplateForHostMiddleware“,”mezzanine.core.middleware.AdminLoginInterfaceSelectorMiddleware“,”mezzanine.core.middleware.SitePermissionMiddleware“,

    Uncomment the following if using any of the SSL settings: 如果使用任何SSL设置,请取消注释以下内容:

    "mezzanine.core.middleware.SSLRedirectMiddleware", “mezzanine.core.middleware.SSLRedirectMiddleware”

    "mezzanine.pages.middleware.PageMiddleware", .... ```` “mezzanine.pages.middleware.PageMiddleware”,....````
  4. Add some INSTALLED_APPS that Mezzanine is expecting: .... "mezzanine.boot", "mezzanine.conf", "mezzanine.core", "mezzanine.generic", "mezzanine.blog", "mezzanine.forms", "mezzanine.pages", "mezzanine.galleries", "mezzanine.twitter", .... 添加Mezzanine期待的一些INSTALLED_APPS: .... "mezzanine.boot", "mezzanine.conf", "mezzanine.core", "mezzanine.generic", "mezzanine.blog", "mezzanine.forms", "mezzanine.pages", "mezzanine.galleries", "mezzanine.twitter", ....
  5. Add references to the template folders of mezzanine to your TEMPLATE_DIRS tuple os.path.join(BASE_PARENT, '<path to mezzanine>/mezzanine/mezzanine'), os.path.join(BASE_PARENT, '<path to mezzanine>/mezzanine/mezzanine/blog/templates'), mezzanine模板文件夹的引用添加到TEMPLATE_DIRS元组os.path.join(BASE_PARENT, '<path to mezzanine>/mezzanine/mezzanine'), os.path.join(BASE_PARENT, '<path to mezzanine>/mezzanine/mezzanine/blog/templates'),
  6. Finally, if your like me, you'll have to override some of the extends paths in the mezzanine templates, the most obvious being in "blog_post_list.html" which just extends base.html , instead you want it to extend the mezzanine specific base file. 最后,如果你喜欢我,你必须覆盖夹层模板中的一些extends路径,最明显的是“blog_post_list.html”,它只是扩展了base.html ,而你希望它扩展夹层特定的base文件。 So go to that file and replace the {% extends "base.html" %} with {% extends "core/templates/base.html" %} . 所以转到该文件并用{% extends "core/templates/base.html" %}替换{% extends "base.html" %} {% extends "core/templates/base.html" %}

This is covered in the FAQs: 这包含在常见问题解答中:

http://mezzanine.jupo.org/docs/frequently-asked-questions.html#how-can-i-add-mezzanine-to-an-existing-django-project http://mezzanine.jupo.org/docs/frequently-asked-questions.html#how-can-i-add-mezzanine-to-an-existing-django-project

TLDR: Mezzanine adds a handful of settings, apps, middleware and context processors, all defined in its default settings.py file - you just need to extract enough of those, depending on your needs. TLDR:Mezzanine添加了一些设置,应用程序,中间件和上下文处理器,都在其默认的settings.py文件中定义 - 您只需根据需要提取足够的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM