简体   繁体   中英

django-cms absolute urls to pages

I want to get a list of all pages I have published in my Django-CMS application but I can't seem to get it to render the language-specific urls.

in my settings I have specified:

LANGUAGES = [
    ('sv', 'Svenska'),
    ('en', 'English'),
]

I go in to the admin site, I create a contact-page (That is not site-home) and set different slugs on different languages, 'contact-sv' and 'contact-en' for instance.

Then I have a view that gets a page

from cms.models import Page
page = Page.objects.published()[1]
print 'swe:', page.get_absolute_url(language='sv')
print 'eng:', page.get_absolute_url(language='en')

I then get This output:

swe: /contact-en/
eng: /contact-en/

When I expected the swe-url to be /sv/contact-sv/

I don't need the langage prefix to the path, I can prepend that to the path but I need the language specific path.

我可以为您提供比等待 2.4 版本更好的解决方案,该版本将使用 Django 的内置 i18n_urlpatterns 来处理这个问题,这应该可以解决您遇到的问题,目前,您的答案是唯一的出路。

I bet there is a better way to do it but now I loop through titles on the page object.

for title in page.title_set.all():
    print title.language, title.slug

It works, but I do not like it...

Maybe you could use the sitemap strategy. django cms has it's own sitemap class that runs this code:

class CMSSitemap(Sitemap):
    changefreq = "monthly"
    priority = 0.5

    def items(self):
        all_titles = Title.objects.public().filter(
            Q(redirect='') | Q(redirect__isnull=True),
            page__login_required=False,
            page__site=Site.objects.get_current(),
        ).order_by('page__path')
        return all_titles

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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