Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango retrieve data from db to complete a url pattern
    primarykey
    data
    text
    <p>I know this is an easy question, I am just not getting something...so thank you for your patience and advice.</p> <p>I have a view that asks a user to register to use our app. The data he/she submits is stored in a database and he is sent off to another page to set up the application:</p> <pre><code>#views.py def regPage(request, id=None): form = RegForm(request.POST or None, instance=id and UserRegistration.objects.get(id=id)) # Save new/edited pick if request.method == 'POST' and form.is_valid(): form.save() return HttpResponseRedirect('/dev/leaguepage/') user_info = UserRegistration.objects.all() context = { 'form':form, 'user_info' :user_info, } return render(request, 'regpage.html', context) </code></pre> <p>Rather than sending ALL users to the same page '/dev/leaguepage/', I need to send each user to his own page based on the PK in the database like: '/dev/PrimaryKey/' I am not sure how to make this happen either on the views file or in the URLs.py file:</p> <pre><code>#urls.py from django.conf.urls.defaults import patterns, include, url from acme.dc_django import views urlpatterns = patterns('', url(r'^leaguepage/$','acme.dc_django.views.leaguePage'), url(r'^$', 'acme.dc_django.views.regPage'), ) </code></pre> <p>Thank you for your help!</p> <p>dp</p> <p>Updated code:</p> <pre><code>#url url(r'^user/(?P&lt;id&gt;\d+)/$','acme.dc_django.views.leaguePage', name="league_page"), #view def regPage(request, id): form = RegForm(request.POST) # Save new/edited pick if request.method == 'POST' and form.is_valid(): form.save() return HttpResponseRedirect(reverse('league_page', kwargs={'id' :id})) #return HttpResponseRedirect('/dev/leaguepage/') user_info = UserRegistration.objects.all() context = { 'form':form, 'user_info' :user_info, } return render(request, 'regpage.html', context) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload