在url中设置参数

时间:2014-06-02 22:23:44

标签: python django django-views

我正在尝试将我的网址设置为这样使用:

domain.com/obrigado/?transaction_id=526D59DD-FD70-4CAE-B321-14B1F69D60D3

在我的urls.py中

我这样设置:

url(r'^obrigado/(?P<transaction_id>[^\.]+)', 'simulado.views.obrigado'),

但这会返回错误:

DoesNotExist at /obrigado/
Quiz matching query does not exist.

这是我的观点:

@login_required
def obrigado(request, transaction_id):
    return render(request, 'obrigado.html')

如何更改网址?

编辑:

这是完整的追溯:

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.

这是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是空的。

1 个答案:

答案 0 :(得分:0)

这里使用的网址是:

domain.com/thanks/?transaction_id=XXXXX

在您的urls.py中,正则表达式没有单词thanks。这可能是错误的原因。