Password protected URLs Django - choose which to be protected also in admin
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
http://www.example.com/category1/
http://www.example.com/category2/
http://www.example.com/category3/
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:
http://www.example.com/category1/
http://www.example.com/category3/
Without login:
http://www.example.com/category2/
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
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Yy-xRUBCDU8J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home