簡體   English   中英

django-cms中的url設計

[英]url design in django-cms

我正在使用django-cms設計一個網站,截至目前,我必須創建一個基本的主頁,其中包含諸如About UsProductsContact Us等菜單欄,

我已經完成了djangodjango-cms所有必要設置,激活了admin部分,並且運行正常。

我創建了一個包含“ About UsProductsContact UsHome Page template ,並通過django-cms admin和一個called的about-us創建了一個名為aboutus的頁面。

現在,我已經給了“ slug about-us ,這只是“ About Us菜單的錨標記中的URL,因此,當我單擊鏈接時,它的工作正常,並將我重定向到頁面aboutus ,瀏覽器中的URL為http://localhost:8080/aboutus

但是問題是,當我再次單擊aboutus鏈接時,它兩次生成url,就像http://localhost:8080/aboutus/aboutus ,我的意思是每次點擊時,slug aboutus都會追加到該URL。

以下是我的代碼

settings.py

TEMPLATE_CONTEXT_PROCESSORS = (
     .......
    'cms.context_processors.media',
    'sekizai.context_processors.sekizai',
)
CMS_TEMPLATES = (
    ('home.html', gettext('Home')),
    ('aboutus.html', gettext("About Us")),
    ('management_team.html',gettext('Management Team')),
)
.....
....

urls.py

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

admin.autodiscover()

urlpatterns = patterns('',

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

home.html的

{% load cms_tags sekizai_tags %}
{% load staticfiles %}
{% load staticfiles %}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>{% block head %}{% endblock %}</title>
      {% render_block "css" %}
  </head>
  <body>
      {% cms_toolbar %}
        <div class="submenu">
            <a href="about-us">About Company Services</a><br />
            <a href="management-team">Our Management Team</a>
        </div>
        <a href="about-us" class="menu aboutus">About Us</a></div>
      {% render_block "js" %}
  </body>
</html>

以上是我的總體代碼,其中home.html使用以下菜單顯示帶有菜單的主頁(通過使用某些CSS樣式)

   About Us
        About Company Services 
        Our Management Team

因此,當我單擊“ About Us ”鏈接時,生成的URL是http://localhost:8000/about-us/ ,當我們單擊“ About Company Services ,生成的URL立即是http://localhost:8000/about-us/about-ushttp://localhost:8000/about-us/about-us/our-management-team/立即單擊Our Management Team 因此,該網址將附加到之前的網址,而不是附加到domain name

我已經使用django-cms admin中創建的模板創建了所有頁面

   Page Name                slug

   About Us                 about-us
   About Company Services   about-us 
   Our Management Team      our-management-team 

那么,上面的代碼有什么問題,為什么這些URL追加到以前的URL而不是追加到域?

如何從django-cms管理員到parent(About Us)創建一個childs(About Company Services,Our Management Team ) parent(About Us)

實際上我想在About Us頁面下創建兩個頁面(About Company Services,Our Management Team )About Us如何在django-cms admin中實現此目的

任何人都可以請讓我知道在Django-CMS菜單的概念,我曾嘗試和閱讀的文檔django-cms many many many times ,但無法理解的概念, menus等等走近SO

如果這是您在管理部分( /admin/cms/page )中的頁面布局:

- Home (level=0)
    - About Us (level=1)
        - About Company Services (level=2)
            - Foo Bar (level=3)
        - Our Management Team (level=2)
    - Some Other Section (level=1)
        - Some Sub Section (level=2)
    - ...

當您打印{% show_menu ABCD %}您正在渲染ul菜單,其中A,B,C和D是用於指定菜單配置的數字。

A = Start
B = End
C = Inactive
D = Active

因此{% show_menu 1 2 0 100 %}

  • A=1表示從級別1開始導航,即不包括級別0的Home
  • B=2表示將導航降低到2級,即排除Foo Bar
  • C=0表示對於不活動的路徑,顯示0級。 因此,如果我們當前位於“ About Us頁面上,則在“ Some Other Section下面的菜單中將看不到任何鏈接(因為這是不活動的蹤跡),但是我們仍然會看到“ About Company...Out Management... ”這是一條活躍的小徑)
  • D=100表示對於當前活動的跟蹤,顯示到100個級別(這就是我們看到上述“ About Company...Our Management

所以結果是:

- About Us (level=1)
    - About Company Services (level=2)
    - Our Management Team (level=2)
- Some Other Section (level=1)

使用{%show_menu%}模板標記來呈現菜單。 請務必也閱讀該文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM