将GET参数从python视图传递给temp

2024-07-04 05:44:59 发布

您现在位置:Python中文网/ 问答频道 /正文

很简单,我在获取GET参数d的值时遇到了困难

我点击的链接如下:

http://127.0.0.1:8000/Account/Site/d=mysite.com

^{服务的view是:

^{pr2}$

具体来说,这一行:

DomainToScan = request.GET.get('d')

当查看django模板时,DomainToScan的值作为None输出

我做错什么了?在

谢谢你!在

更新:

urls.py

(r'^Account/Site/[?]d=[A-za-z0-9]{2,50}.[a-z]{1,3}$', Site),

由于某些原因,这与以下url不匹配:

http://127.0.0.1:8000/Account/Site/?d=mysite.com

有什么原因吗?Rubular表示它有效


Tags: djangocomviewhttp参数get链接request
2条回答

你没有任何GET参数。如果您希望domain成为GET参数,那么您的链接应该是http://127.0.0.1:8000/Account/Site/?d=mysite.com-注意?。在

(另请注意,您实际上需要returnHttpResponseRedirect(),而不仅仅是调用它:但整个is_authenticated检查无论如何都是毫无意义的,因为函数是用login峈required修饰的,因此未经身份验证的用户甚至不会进入该视图。)

尝试:

@login_required
def Site(request, DomainToScan=None):
    if request.user.is_authenticated():
        # verify domain in url is associated with authenticated users account
        VerifyDomainAgainstDb = Tld.objects.filter(FKtoClient=request.user,domainNm=DomainToScan)
    else:
        return HttpResponseRedirect("/Login/")
    return render(request, 'VA/account/begin_site.html', locals())

在网址.py在

^{pr2}$

相关问题 更多 >

    热门问题