本文整理匯總了Python中django.shortcuts.reverse方法的典型用法代碼示例。如果您正苦於以下問題:Python shortcuts.reverse方法的具體用法?Python shortcuts.reverse怎麽用?Python shortcuts.reverse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.shortcuts
的用法示例。
在下文中一共展示了shortcuts.reverse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: scan_scan_list
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def scan_scan_list(request: HttpRequest, scan_list_id: int) -> HttpResponse:
"""Schedule the scan of a scan list."""
scan_list = get_object_or_404(
ScanList.objects.prefetch_related(Prefetch(
'sites',
queryset=Site.objects.select_related('last_scan') \
.annotate_most_recent_scan_start() \
.annotate_most_recent_scan_end_or_null())
), pk=scan_list_id)
was_any_site_scannable = scan_list.scan()
if was_any_site_scannable:
num_scanning_sites = Scan.objects.filter(end__isnull=True).count()
messages.success(request,
_("Scans for this list have been scheduled. "+ \
"The total number of sites in the scanning queue "+ \
"is %i (including yours)." % num_scanning_sites))
else:
messages.warning(request,
_('All sites have been scanned recently. Please wait 30 minutes and try again.'))
return redirect(reverse('frontend:view_scan_list', args=(scan_list_id,)))
示例2: get
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def get(self, request):
if not request.user.is_staff and not request.user.is_superuser:
messages.error(request, "You do not have the rights to index peer records.")
return redirect(reverse("home"))
last_synchronization = PeeringDB().get_last_synchronization()
sync_time = last_synchronization.time if last_synchronization else 0
context = {
"last_sync_time": sync_time,
"peeringdb_contact_count": Contact.objects.count(),
"peeringdb_network_count": Network.objects.count(),
"peeringdb_networkixlan_count": NetworkIXLAN.objects.count(),
"peer_record_count": PeerRecord.objects.count(),
}
return render(request, "peeringdb/cache.html", context)
示例3: delete
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def delete(request):
try:
if request.session.get('player'):
print('[view.yata.delete] delete account')
tId = request.session["player"].get("tId")
player = Player.objects.filter(tId=tId).first()
factionId = player.factionId
faction = Faction.objects.filter(tId=factionId).first()
try:
faction.delKey(tId)
faction.save()
except BaseException:
pass
player.delete()
del request.session['player']
print('[view.yata.delete] redirect to logout')
return HttpResponseRedirect(reverse('logout'))
except Exception as e:
return returnError(exc=e, session=request.session)
示例4: upload_dataproduct
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def upload_dataproduct(context, obj):
user = context['user']
initial = {}
if isinstance(obj, Target):
initial['target'] = obj
initial['referrer'] = reverse('tom_targets:detail', args=(obj.id,))
elif isinstance(obj, ObservationRecord):
initial['observation_record'] = obj
initial['referrer'] = reverse('tom_observations:detail', args=(obj.id,))
form = DataProductUploadForm(initial=initial)
if not settings.TARGET_PERMISSIONS_ONLY:
if user.is_superuser:
form.fields['groups'].queryset = Group.objects.all()
else:
form.fields['groups'].queryset = user.groups.all()
return {'data_product_form': form}
示例5: get
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def get(self, request, code):
code_obj = EmailVerifyCode.objects.filter(code=code, type='register').last() # last取默認排序後的最後一個
# timestamp = (now() - code_obj.add_time).total_seconds()
# 驗證碼過期以後再做吧, 不然又得要寫多一個重發驗證碼
if code_obj: # and timestamp < 600:
user = get_object_or_404(User, email=code_obj.email, is_active=False)
user.is_active = True
code_obj.is_used = True
user.save()
code_obj.save()
login(request, user)
messages.success(request, '激活成功, 歡迎加入本博客係統')
return redirect(reverse('blog:index'))
messages.success(request, '驗證碼有誤')
return redirect(reverse('user:login'))
示例6: test_member_add
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def test_member_add(full_testdata, logged_in_client, user):
response = logged_in_client.get(reverse("office:members.add"), follow=True)
assert response.status_code == 200
response = logged_in_client.post(
reverse("office:members.add"),
{
"member__number": "23",
"member__name": "Torsten Est",
"membership__start": str(now().date()),
"membership__interval": "1",
"membership__amount": "10",
},
follow=True,
)
assert response.status_code == 200
assert b'"alert alert-success"' in response.content
assert response.resolver_match.url_name == "members.data"
示例7: test_transaction_detail
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def test_transaction_detail(full_testdata, logged_in_client, user):
# Balanced transaction
response = logged_in_client.get(
reverse("office:finance.transactions.detail", kwargs={"pk": 1}), follow=True
)
assert response.status_code == 200
# Unbalanced transaction, credit
response = logged_in_client.get(
reverse("office:finance.transactions.detail", kwargs={"pk": 167}), follow=True
)
assert response.status_code == 200
# Unbalanced transaction, debit
response = logged_in_client.get(
reverse("office:finance.transactions.detail", kwargs={"pk": 163}), follow=True
)
assert response.status_code == 200
示例8: register
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def register(request):
if request.method == 'POST':
form = RegisterForm(request.POST)
if form.is_valid():
data = form.cleaned_data
user = User.objects.create_user(
username=data['username'],
password=data['password'],
email=data['email'],
)
user.first_name = data.get('first_name')
user.last_name = data.get('last_name')
user.is_confirmed = False
user.save()
messages.success(request, '你成功注冊了一個用戶')
redirect_url = reverse('Content:index')
return redirect(redirect_url)
else:
form = RegisterForm()
return render(request, 'Auth/register.html', context={
'form': form,
})
示例9: avatar_edit
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def avatar_edit(request):
if request.method == 'POST':
form = AvatarForm(request.POST, request.FILES)
if form.is_valid():
request.user.avatar = form.cleaned_data['avatar']
request.user.save()
messages.success(request, '成功修改頭像')
redirect_url = reverse('User:avatar_edit')
return redirect(redirect_url)
else:
form = AvatarForm()
form.data['avatar'] = request.user.avatar
return render(request, 'Auth/avatar_edit.html', context={
'form': form,
})
示例10: password_change
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def password_change(request):
if request.method == 'POST':
form = PasswordChangeForm(request.POST)
form.user = request.user
if form.is_valid():
password = form.cleaned_data['new_password1']
request.user.set_password(password)
request.user.save()
logout(request)
messages.success(request, '成功修改密碼,請重新登陸')
redirect_url = reverse('User:login')
return redirect(redirect_url)
else:
form = PasswordChangeForm()
return render(request, 'Auth/password_change.html', context={
'form': form,
})
示例11: add_node
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def add_node(request):
if request.method == 'POST':
form = AddNodeForm(request.POST, request.FILES)
if form.is_valid():
form.save()
messages.success(request, "成功增加節點")
slug = form.instance.slug
redirect_url = reverse('Content:book', kwargs={'slug': slug})
return redirect(redirect_url)
else:
form = AddNodeForm()
context = {
'form': form,
}
return render(request, 'Content/add_node.html', context=context)
示例12: add_publishing
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def add_publishing(request):
if request.method == 'POST':
form = AddPublishingForm(request.POST)
if form.is_valid():
form.save()
messages.success(request, '你成功添加了一個出版社,現在可以為其增添書籍')
redirect_url = reverse('Content:add_node')
return redirect(redirect_url)
else:
form = AddPublishingForm()
context = {
'form': form
}
return render(request, 'Content/add_publishing.html', context=context)
示例13: add_tag
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def add_tag(request):
if request.method == 'POST':
form = AddTagForm(request.POST)
if form.is_valid():
form.save()
messages.success(request, '你成功添加了一個tag,現在可以用其添加書籍')
redirect_url = reverse('Content:add_node')
return redirect(redirect_url)
else:
form = AddTagForm()
context = {
'form': form,
}
return render(request, 'Content/add_tag.html', context=context)
示例14: delete_event_searchable
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def delete_event_searchable(event):
site = Site.objects.get(id=1)
if settings.DEBUG:
schema = "http"
else:
schema = "https"
event_url = "%s://%s%s" % (schema, site.domain, event.get_absolute_url())
origin_url = "%s://%s%s" % (schema, site.domain, reverse("searchables"))
md5 = hashlib.md5()
federation_url = event_url.split("/")
federation_node = "/".join(federation_url[:3])
federation_id = "/".join(federation_url[:5])
md5.update(bytes(federation_id, "utf8"))
event_uri = federation_node + "/" + md5.hexdigest()
try:
searchable = Searchable.objects.get(event_uri=event_uri)
searchable.delete()
except:
pass
示例15: page_view
# 需要導入模塊: from django import shortcuts [as 別名]
# 或者: from django.shortcuts import reverse [as 別名]
def page_view(
request: http.HttpRequest,
pk: int,
workflow: Optional[models.Workflow] = None,
) -> http.HttpResponse:
"""View the content of one of the logs.
:param request: Http Request received
:param pk: Primary key of the log to view
:param workflow: Workflow being manipulated (set by the decorators)
:return: Http response rendering the view.html
"""
# Get the log item
log_item = workflow.logs.filter(pk=pk, user=request.user).first()
# If the log item is not there, flag!
if not log_item:
messages.error(request, _('Incorrect log number requested'))
return redirect(reverse('logs:index'))
return render(
request,
'logs/view.html',
{'log_item': log_item, 'c_vals': log_item.payload})