本文整理汇总了Python中django.core.urlresolvers.reverse方法的典型用法代码示例。如果您正苦于以下问题:Python urlresolvers.reverse方法的具体用法?Python urlresolvers.reverse怎么用?Python urlresolvers.reverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.urlresolvers
的用法示例。
在下文中一共展示了urlresolvers.reverse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: close
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def close(request, pk):
"""Close this Service Order."""
order = get_object_or_404(Order, pk=pk)
if request.method == 'POST':
try:
order.close(request.user)
except Exception as e:
messages.error(request, e)
return redirect(order)
if request.session.get("current_order_id"):
del(request.session['current_order_id'])
del(request.session['current_order_code'])
del(request.session['current_order_customer'])
messages.success(request, _('Order %s closed') % order.code)
return redirect(order)
data = {'order': order, 'action': reverse(close, args=[pk])}
return render(request, "orders/close.html", data)
示例2: accessories
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def accessories(request, pk, device_id):
from django.utils import safestring
if request.POST.get('name'):
a = Accessory(name=request.POST['name'])
a.order_id = pk
a.device_id = device_id
a.save()
choice_list = []
choices = Accessory.objects.distinct('name')
for c in choices:
choice_list.append(c.name)
action = reverse('orders-accessories', args=[pk, device_id])
selected = Accessory.objects.filter(order_id=pk, device_id=device_id)
choices_json = safestring.mark_safe(json.dumps(choice_list))
return render(request, 'devices/accessories_edit.html', locals())
示例3: __init__
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def __init__(self, *args, **kwargs):
super(NoteForm, self).__init__(*args, **kwargs)
note = kwargs['instance']
self.fields['sender'] = forms.ChoiceField(
label=_('From'),
choices=note.get_sender_choices(),
widget=forms.Select(attrs={'class': 'span12'})
)
self.fields['body'].widget = AutocompleteTextarea(
rows=20,
choices=Template.templates()
)
if note.order:
url = reverse('notes-render_template', args=[note.order.pk])
self.fields['body'].widget.attrs['data-url'] = url
示例4: site_login
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def site_login(request):
"""
Logs in current user
:param request:
:return render:
"""
if request.method == "POST":
user = None
user_login = request.POST['login']
user_password = request.POST['password']
print("Login tryout by "+user_login)
if user_login != "" and user_password != "":
user = authenticate(username=user_login, password=user_password)
if user is not None:
login(request, user)
return HttpResponseRedirect(reverse('public_gate:home'))
else:
# User.objects.create_user(user_login, '', user_password).save()
return render(request, 'public_gate/home.html', {"error_message": "Wrong login/password combination"})
return render(request, 'public_gate/home.html', {"error_message": "One or more fields are empty"})
示例5: hijack_field
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def hijack_field(self, obj):
hijack_attributes = hijack_settings.HIJACK_URL_ALLOWED_ATTRIBUTES
if 'user_id' in hijack_attributes:
hijack_url = reverse('hijack:login_with_id', args=(obj.pk, ))
elif 'email' in hijack_attributes:
hijack_url = reverse('hijack:login_with_email', args=(obj.email, ))
else:
hijack_url = reverse('hijack:login_with_username', args=(obj.username, ))
button_template = get_template(hijack_admin_settings.HIJACK_BUTTON_TEMPLATE)
button_context = {
'hijack_url': hijack_url,
'username': str(obj),
}
return button_template.render(button_context)
示例6: item_link
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def item_link(self, job):
return reverse('job-show', args=[job.pk])
示例7: get_absolute_url
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def get_absolute_url(self):
return reverse('job-show', args=[str(self.id)])
示例8: test_index_returns_200
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def test_index_returns_200(self):
response = self.client.get(reverse("job-home"))
self.assertEquals(response.status_code, 200)
示例9: test_index_list_active_jobs
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def test_index_list_active_jobs(self):
mommy.make(Job, status=0)
response = self.client.get(reverse("job-home"))
self.assertEquals(len(response.context["jobs"]), 1)
示例10: test_show_returns_200
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def test_show_returns_200(self):
response = self.client.get(reverse("job-show", args=[self.job.pk]))
self.assertEquals(response.status_code, 200)
示例11: test_show_inactive_job_returns_404
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def test_show_inactive_job_returns_404(self):
job = mommy.make(Job, status=0)
response = self.client.get(reverse("job-show", args=[job.pk]))
self.assertEquals(response.status_code, 404)
示例12: test_new_returns_200
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def test_new_returns_200(self):
response = self.client.get(reverse("job-new"))
self.assertEquals(response.status_code, 200)
示例13: test_new_template
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def test_new_template(self):
response = self.client.get(reverse("job-new"))
self.assertTemplateUsed(response, "new.html")
示例14: test_create_new_job
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def test_create_new_job(self):
self.job.pk = 0
params = model_to_dict(self.job)
response = self.client.post(reverse("job-new"), params)
self.assertEquals(response.status_code, 302)
示例15: test_edit_returns_200
# 需要导入模块: from django.core import urlresolvers [as 别名]
# 或者: from django.core.urlresolvers import reverse [as 别名]
def test_edit_returns_200(self):
response = self.client.get(reverse("job-edit", args=[self.job.token]))
self.assertEquals(response.status_code, 200)