TAGS :Viewed: 10 - Published at: a few seconds ago
[ Setting up a paramenter in url ]
I'm trying to setup my url to be used like this:
domain.com/obrigado/?transaction_id=526D59DD-FD70-4CAE-B321-14B1F69D60D3
In my urls.py
I'm setting it like this:
url(r'^obrigado/(?P<transaction_id>[^\.]+)', 'simulado.views.obrigado'),
But this returns an error:
DoesNotExist at /obrigado/
Quiz matching query does not exist.
And this is my view:
@login_required
def obrigado(request, transaction_id):
return render(request, 'obrigado.html')
How should a change the url conf?
EDIT:
This is the full traceback:
Environment:
Request Method: GET
Request URL: http://queromaiseducacao.com.br/obrigado/?transaction_id=BD7B0E7A-E27F-41BE-963F-93D13D8E5107
Django Version: 1.6.5
Python Version: 2.7.5
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'simulado',
'south',
'multichoice',
'django.contrib.admin',
'social_auth')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/home/filipefr2/webapps/quiz/lib/python2.7/django/core/handlers/base.py" in get_response
112. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/filipefr2/webapps/quiz/quiz/simulado/views.py" in quiz_take
80. quiz = Quiz.objects.get(url=quiz_name.lower())
File "/home/filipefr2/webapps/quiz/lib/python2.7/django/db/models/manager.py" in get
151. return self.get_queryset().get(*args, **kwargs)
File "/home/filipefr2/webapps/quiz/lib/python2.7/django/db/models/query.py" in get
310. self.model._meta.object_name)
Exception Type: DoesNotExist at /obrigado/
Exception Value: Quiz matching query does not exist.
this is the ulrs.py:
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'quiz.views.home', name='home'),
# url(r'^quiz/', include('quiz.foo.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
####################
# quiz base url
url(r'^$', 'simulado.views.index'),
# quiz category list
url(r'^category/(?P<slug>[^\.]+)', 'simulado.views.view_category', name='view_quiz_category'),
#django social auth
url(r'', include('social_auth.urls')),
# cart
url(r'^carrinho$', 'simulado.views.carrinho'),
url(r'^buyItem$', 'simulado.views.buyItem', name = "buyItem"),
# obrigado, return from pagseguro
url(r'^obrigado/(?P<transaction_id>[\w]+)/', 'simulado.views.obrigado'),
# progress
url(r'^progress/$', 'simulado.views.progress'),
url(r'^progress$', 'simulado.views.progress'),
# passes variable 'quiz_name' to quiz_take view
url(r'^(?P<quiz_name>[\w-]+)/$',
'simulado.views.quiz_take'), # quiz/
url(r'^(?P<quiz_name>[\w-]+)$/',
'simulado.views.quiz_take'), # quiz
url(r'^(?P<quiz_name>[\w-]+)/take/$',
'simulado.views.quiz_take'), # quiz/take/
url(r'^(?P<quiz_name>[\w-]+)take$',
'simulado.views.quiz_take'), # quiz/take
)
Obrigado.html is empty.
Answer 1
The url being used here is:
domain.com/thanks/?transaction_id=XXXXX
while in your urls.py
, the regex does not have the word thanks
. That could be the cause of the error.