Hello,
I have quite interesting problem with password protected content in Django. I can successfully protect my content or URLs in Django by using "@login_required" decorator.
Example:
**Urls.py**
urlpatterns = patterns('',
url(r'^(?P<category_categoryurl>[a-zA-Z0-9_.-]+)/$', 'example.sort'),
)
**Views.py**
@login_required
def categorysort(request, category_categoryurl):
latest_images_list2 = Category.objects.all().filter(categoryurl=category_categoryurl)
return render_to_response('category.html', {'latest_images_list': latest_images_list})
So basically this example would work like this:
Dynamic urls from DB all protected by password - because of "@login_required" decorator
What I want to achieve is that for example in admin I want to specify that some pages are with login and some not like in the example that with login:
Without login:
That during creation in admin specifying the url (thats easy) but also specify with checkmark do not need to login something like that.
Can I use python in the views:
If in db in Category login=True
do this:
@login_required
def categorysort(request, category_categoryurl):
latest_images_list2 = Category.objects.all().filter(categoryurl=category_categoryurl)
return render_to_response('category.html', {'latest_images_list': latest_images_list})
if Category login=False
do this:
def categorysort(request, category_categoryurl):
latest_images_list2 = Category.objects.all().filter(categoryurl=category_categoryurl)
return render_to_response('category.html', {'latest_images_list': latest_images_list})
Disregard the syntax only explaining where I am going.
Can you help me?
Thanks