[Answer]-Create and redirect to slug urls in django

1👍

First question:

url(r'^doctor/(?P<name>\w+)/$', views.showDocProfileByName),

Second question:

def showDocProfileById(request, id):
    doctor = Doctor.objects.get(id=id)
    name = doctor.name.replace(' ', '-')

    HttpResponseRedirect(reverse('project.views.showDocProfileByName', args=(name)))
👤torm

0👍

You could just allow the user to input either id or doctor name

url(r'^docprofile/(?P<identifier>(\d+|\w+))', views.showDocProfile, name='showDocProfile')
👤Greg

Leave a comment