I've got a function based view in Django called userView
@login_required(login_url='/login/')
def userView(request):
user = None
if request.user.is_authenticated():
user = request.user
user_id = user.pk
return render(request, "user_view.html", {'user': user})
and here's my URL for it
urlpatterns = [
url(r'^user/', userView, name='user'),
]
After my user has logged in, I'd like him to see his pk number in the URL. I.e., if the user's PK is 3 and the user directs their browser to www.myapp.com/user, the URL in the address bar should change to www.myapp.com/user/3/. How do I make that happen? I'm aware I need to edit the RegEx for the URL into
url(r'^user/(?P<user_id>[0-9]+)/$', userView, name='user')
but how do I pass the PK number to the URL?
www.myapp.com/user/you want the URL to change towww.myapp.com/user/3/(if the user's PK is 3)?