本文整理匯總了Python中django.core.urlresolvers.reverse_lazy方法的典型用法代碼示例。如果您正苦於以下問題:Python urlresolvers.reverse_lazy方法的具體用法?Python urlresolvers.reverse_lazy怎麽用?Python urlresolvers.reverse_lazy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.core.urlresolvers
的用法示例。
在下文中一共展示了urlresolvers.reverse_lazy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: send_email
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def send_email(self, regenerate=False):
if not self.verification_code or regenerate:
self.generate_token()
context = dict(
verification_code=self.verification_code,
first_name=self.owner.first_name,
accounts_reset_password_link='http://%s%s' % (
get_current_site().domain,
reverse_lazy('accounts_reset_password', args=(self.id,))
)
)
email(
recipient=[self.owner.email],
context=context,
template_name='password_reset'
)
示例2: index
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def index(request):
if not user_model.objects.filter(is_staff=True).exists():
return HttpResponseRedirect(reverse_lazy('welcome_staff'))
content = Content.objects.published().order_by('published_at').first()
random_book = Book.objects.available().order_by('?').first()
random_doc = Document.objects.order_by('?').first()
staff_cards = settings.STAFF_HOME_CARDS
builtin_cards = build_builtin_card_info()
extra_cards = build_extra_app_card_info()
custom_cards = settings.CUSTOM_CARDS
package_cards = build_package_card_info()
cards = (
staff_cards + builtin_cards + extra_cards + custom_cards +
package_cards)
context = {
'blog_content': content,
'random_book': random_book,
'random_doc': random_doc,
'cards': cards,
}
return render(request, 'index.html', context)
示例3: test_post_checkout
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def test_post_checkout(self):
"""
Test correctly posting to the checkout view
"""
country = CountryFactory()
request = RequestFactory().post(
reverse_lazy('longclaw_checkout_view'),
{
'shipping-name': 'bob',
'shipping-line_1': 'blah blah',
'shipping-postcode': 'ytxx 23x',
'shipping-city': 'London',
'shipping-country': country.pk,
'email': 'test@test.com'
}
)
request.session = {}
bid = basket_id(request)
BasketItemFactory(basket_id=bid)
response = CheckoutView.as_view()(request)
self.assertEqual(response.status_code, 302)
示例4: get
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def get(self, request, *args, **kwargs):
""" Makes a clone within the current mission of a specified test case """
# Verify the test case passed is an int and within the path's mission
id_to_clone = int(self.kwargs['pk'])
passed_mission_id = int(self.kwargs['mission'])
try:
test_case = TestDetail.objects.get(pk=id_to_clone)
except TestDetail.DoesNotExist:
return HttpResponse("Test case not found.", status=404)
if test_case.mission.id != passed_mission_id:
return HttpResponse("Test case not linked to specified mission.", status=400)
test_case.pk = None
test_case.test_case_status = 'NEW'
test_case.save()
return HttpResponse(reverse_lazy('mission-test-edit',
kwargs={'mission': test_case.mission.id, 'pk': test_case.pk}))
示例5: get_form_kwargs
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def get_form_kwargs(self, *args, **kwargs):
form_kwargs = super().get_form_kwargs(*args, **kwargs)
try:
user_id = self.request.session['password_reset_id']
user = User.objects.get(id=user_id)
form_kwargs['user'] = user
except KeyError:
message = _(
"You must first verify your token before resetting password."
" Click <a href='{url}'>here</a> to get the password reset"
" verification token. ")
message = format_html(message.format(
url=reverse_lazy('account:account_reset_password')))
messages.add_message(self.request, messages.ERROR, message)
return form_kwargs
示例6: form_valid
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def form_valid(self, form):
login = form.cleaned_data['login']
user = form.user
if (login == user.username and
not user.phone_verified and
not user.email_verified):
user.is_active = False
user.save()
messages.add_message(
self.request, messages.ERROR, account_inactive)
return redirect(reverse_lazy('account:resend_token'))
if(login == user.email and not user.email_verified or
login == user.phone and not user.phone_verified):
messages.add_message(
self.request, messages.ERROR, unverified_identifier)
return redirect(reverse_lazy('account:resend_token'))
else:
return super().form_valid(form)
示例7: post
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def post(self, request, question_pk):
queryset = self.get_queryset()
try:
question = queryset.get(pk=question_pk)
except models.Question.DoesNotExist as e:
raise Http404(e)
try:
choice = question.choice_set.get(pk=request.POST['choice_pk'])
except (KeyError, models.Choice.DoesNotExist):
return render(request, 'polls/detail.html', {
'question': question,
'error_message': 'no choice selected'
})
else:
choice.votes += 1
choice.save()
redirect_url = reverse_lazy('polls:tpl-poll-result', args=(question.pk,))
return HttpResponseRedirect(redirect_url)
示例8: test_request_token_with_post_method_and_access_key_and_signdata_and_no_login
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def test_request_token_with_post_method_and_access_key_and_signdata_and_no_login(self):
url = reverse_lazy('cas_app:cas-request-token')
serializer = TimedSerializer(self.secret_key)
data = serializer.dumps({'redirect_to': self.redirect_to})
data_extra = {
'HTTP_X_SERVICES_PUBLIC_KEY': self.access_key,
}
response = self.client.post(url, data, content_type='application/json', **data_extra)
response_data = serializer.loads(response.content)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(self.cas_consumer.cas_tokens.count(), 1)
self.assertIn('request_token', response_data)
request_token = response_data['request_token']
url = reverse_lazy('cas_app:cas-user-authentication')
response = self.client.get(url, data={
'request_token': request_token,
})
self.assertEqual(response.status_code, status.HTTP_302_FOUND)
print response
示例9: get_success_url
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def get_success_url(self):
return reverse_lazy('tracker:incident-list')
示例10: get_authenticated_redirect_url
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def get_authenticated_redirect_url(self):
messages.add_message(
self.request,
messages.ERROR,
_('You are already logged in')
)
return reverse_lazy('home_page')
示例11: get_success_url
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def get_success_url(self):
return reverse_lazy('home_page')
示例12: get
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def get(self, request):
logout(request)
return redirect(reverse_lazy('welcome_page'))
示例13: get_login_url
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def get_login_url(self):
if self.request.user.is_authenticated():
return reverse_lazy('home_page')
else:
return reverse_lazy('accounts_register')
示例14: get_admin_url
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def get_admin_url(self):
content_type = ContentType.objects.get_for_model(self.__class__)
return reverse_lazy("admin:%s_%s_change" % (content_type.app_label, content_type.model), args=(self.id,))
示例15: get_login_url
# 需要導入模塊: from django.core import urlresolvers [as 別名]
# 或者: from django.core.urlresolvers import reverse_lazy [as 別名]
def get_login_url(self):
if not self.request.user.is_authenticated():
not_logged_in_error_message(self.request)
return reverse_lazy('accounts_login')
if not self.request.project:
project_not_set_error_message(self.request)
return reverse_lazy('projects_index')