regex - Named groups in Django based off model field? -
i trying replicate url regex equivalent to:
url(r'^members/(?p<username>\w+)/$', 'profiles.views.single'),
while understand taking users exist within database from:
from django.contrib.auth.models import user
i wondering if can change little more unique. i've been reading documentation from: https://docs.djangoproject.com/en/1.8/intro/tutorial04/ still lost.
my question regarding whether or not can use data model named group in regex expression.
example:
from django.db import models django.contrib.auth.models import user class address(models.model): user = models.foreignkey(user) unique_code = models.integerfield(max_length = 5) active = models.booleanfield(default = true)
is somehow possible use 'unique_code' field possible url in regex map like:
url(r'^members/(?p<unique_code>\w+)/$', 'profiles.views.single'),
i trying this, didn't work:
def single(request, unique_id): try: uid = get_object_or_404(address, unique_id=unique_id) final = uid except: raise http404 return render_to_response('single_user.html', locals(), context_instance=requestcontext(request))
try replace unique_id in function unique_code
def single(request, unique_code): try: uid = get_object_or_404(address, unique_code=unique_code) final = uid except: raise http404 return render_to_response('single_user.html', locals(), context_instance=requestcontext(request))
Comments
Post a Comment