Login required for django Flatpages -


is there easy way put login required decorator flatpages? need modify url conf?

   (r'',include('django.contrib.flatpages.urls')), 

thanks, fred

the django flatpage model has registration_required boolean field. set true allow logged-in users view page.

https://code.djangoproject.com/browser/django/trunk/django/contrib/flatpages/models.py

class flatpage(models.model):     url = models.charfield(_('url'), max_length=100, db_index=true)     title = models.charfield(_('title'), max_length=200)     content = models.textfield(_('content'), blank=true)     enable_comments = models.booleanfield(_('enable comments'))     template_name = models.charfield(_('template name'), max_length=70, blank=true,         help_text=_("example: 'flatpages/contact_page.html'. if isn't provided, system use 'flatpages/default.html'."))     registration_required = models.booleanfield(_('registration required'), help_text=_("if checked, logged-in users able view page."))     sites = models.manytomanyfield(site)     class meta:         db_table = 'django_flatpage'         verbose_name = _('flat page')         verbose_name_plural = _('flat pages')         ordering = ('url',)     def __unicode__(self):         return u"%s -- %s" % (self.url, self.title)     def get_absolute_url(self):         return self.url 

alternatively, add following flatpage template:

<!doctype html> <html> <head> <title>{{ flatpage.title }}</title> </head> <body> {% if user.is_authenticated %}     {{ flatpage.content }} {% else %}     please <a href="">log in</a> view page. {% endif %} </body> </html> 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -