mercredi 11 mars 2015

Django urlresolvers reverse for dynamically generated ids

I've got to test URLs that look like this: http://ift.tt/1KWEu9i but I'm not sure how to say this to the reverse() function. This is my urls.py from django.conf.urls import patterns, url from payment import views from payment.msn import *



urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^msnstats/', MsnStats.finish_transaction, name='finish_transaction'),
url(r'^pay/(?P<payment_id>\w+)/$', views.pay, name='pay')
)


And this is what the relevant part of my views.py looks like:



def pay(request, payment_id):
try:
plan=PaymentPlan.objects.get(payment_id=payment_id)


The payment_id is generated for each plan, so I first create a plan, get its payment_id from the database, and somehow call it. I'm just not sure how to use reverse.


Aucun commentaire:

Enregistrer un commentaire