简体   繁体   English

如何在夹层Django中设置菜单

[英]How to set menus in Mezzanine Django

I have created a model.py file in which I define my classes like: 我创建了一个model.py文件,其中定义了我的类,例如:

from django.db import models
from mezzanine.pages.models import Page

class Author(Page):
    dob = models.DateField("Date of birth")

class Book(models.Model):
    author = models.ForeignKey("Author")
    cover = models.ImageField(upload_to="authors")

Then my HTML page and place it into templates folder define URL in urls.py file. 然后将我的HTML页面放入templates folder并在urls.py文件中定义URL。

I run command python manage.py collecttemplates to get all templates 我运行命令python manage.py collecttemplates获取所有模板

Now I browse 127.0.0.1/8000/page1/ to get my page view. 现在,我浏览127.0.0.1/8000/page1/以获取页面视图。

* *Question 1: How to place this page in menu of home page using admin interface? * *问题1:如何使用管理界面将此页面放置在主页菜单中?

Question 2: How to solve this error 'NoneType' object has no attribute 'split' generates if I browse http://127.0.0.1:8000/admin/conf/setting/ ? 问题2:如果我浏览http://127.0.0.1:8000/admin/conf/setting/如何解决此错误'NoneType' object has no attribute 'split'生成?

Question3 : How to access POST DATA from forms created in mezzanine interface? Question3:如何从夹层界面中创建的表单访问POST DATA? * * * *

UPDATE: 更新:

from django.db import models
from mezzanine.pages.models import Page
class Author(Page):
    dob = models.DateField("Date of birth")

class Book(models.Model):
    author = models.ForeignKey("Author")
    cover = models.ImageField(upload_to="authors")

and admin.py with these: 和admin.py与这些:

from django.contrib import admin
from mezzanine.pages.admin import PageAdmin
from .models import Author  

admin.site.register(Author, PageAdmin) admin.site.register(作者,PageAdmin)

Now i write these commands: python manage.py syncdb, python manage.py migrate, 现在,我编写以下命令:python manage.py syncdb,python manage.py migration,
and then open python shell to write Author.objects.create(dob = "12/12/2014") 然后打开python shell编写Author.objects.create(dob =“ 12/12/2014”)

That generates error that author is not defined. 这会产生未定义作者的错误。 It's true because no tables created in my database.?! 的确如此,因为在我的数据库中没有创建任何表。

I assume you're working through the Content Architecture tutorial on the Mezzanine site. 我假设您正在阅读夹层网站上的内容体系结构教程。 The tutorial assumes a lot on your part, which is not ideal for a beginner. 本教程承担了很多工作,对于初学者而言并不理想。 If you haven't seen it, you might want to take a look anyway. 如果您还没有看过,您可能还是要看看。 Here it is: http://mezzanine.jupo.org/docs/content-architecture.html 它在这里: http : //mezzanine.jupo.org/docs/content-architecture.html

To answer Question#1: You add the new content type via the Pages admin: http://127.0.0.1:8000/admin/pages/page/ Select from the drop-down menus that read "Add..." to select its type and on the following configuration page you can select where you want it displayed as a menu link. 回答问题1:您可以通过Pages admin添加新的内容类型: http://127.0.0.1:8000/admin/pages/page/ : http://127.0.0.1:8000/admin/pages/page/ : http://127.0.0.1:8000/admin/pages/page/ admin/pages/ http://127.0.0.1:8000/admin/pages/page/从显示为“ Add ...”的下拉菜单中选择它的类型,然后在下面的配置页面上,您可以选择它在哪里显示为菜单链接。

In response to your UPDATE: 响应您的更新:

At the Djanog/Mezzanine Python shell: 在Djanog / Mezzanine Python外壳上:

from <your app> import models

Then try models.Author.objects.create(title="Dr. Seuss") 然后尝试models.Author.objects.create(title =“ Dr。Seuss”)

No ideas on Questions #2 & #3 right now. 现在对问题2和问题3没有任何想法。

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

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