gpt4 book ai didi

python - 在 django 开发服务器上工作,但不在 apache 上工作

转载 作者:太空宇宙 更新时间:2023-11-03 19:37:07 25 4
gpt4 key购买 nike

我遇到了 apache 服务器的问题,我们编写了代码,如果在表单字段中输入的 url 有效,它将显示一条错误消息,当我通过 django 开发服务器运行代码时,它工作正常,显示错误消息,但是当通过apache运行时,则不显示错误消息,只是返回到该页面本身。下面是 python 和 html 的代码:

<小时/>
objc= {
"addRecipeBttn": "/project/add",
"addRecipeUrlBttn": "/project/add/import",
}

def __showAddRecipe__(request):
global objc
#global objc
if "userid" in request.session:
objc["ErrorMsgURL"]= ""
try:
urlList= request.POST
URL= str(urlList['url'])
URL= URL.strip('http://')
URL= "http://" + URL

recipe= __addRecipeUrl__(URL)

if (recipe == 'FailToOpenURL') or (recipe == 'Invalid-website-URL'):
#request.session["ErrorMsgURL"]= "Kindly check URL, Please enter a valid URL"
objc["ErrorMsgURL"]= "Kindly check URL, Please enter a valid URL"
print "here global_context =", objc
return HttpResponseRedirect("/project/add/import/")
#return render_to_response('addRecipeUrl.html', objc, context_instance = RequestContext(request))
else:
objc["recipe"] = recipe
return render_to_response('addRecipe.html',
objc,
context_instance = RequestContext(request))
except:
objc["recipe"] = ""
return render_to_response('addRecipe.html',
objc,
context_instance = RequestContext(request))
else:
login_redirect['next']= "/project/add/"
return HttpResponseRedirect("/project/login")



def __showAddRecipeUrl__(request):
global objc
if "userid" in request.session:
return render_to_response('addRecipeUrl.html',
objc,
context_instance = RequestContext(request))
else:
login_redirect['next']= "/project/add/import/"
return HttpResponseRedirect("/project/login")
_

HTML 文件:-

请检查并告诉我是否有人可以帮助解决这个问题,它在 django 开发服务器上工作。

谢谢苏海尔

最佳答案

大家好,感谢支持,问题已解决,我就是这样做的。

def showAddRecipe(request):
#global objc
if "userid" in request.session:
objc["ErrorMsgURL"]= ""
try:
urlList= request.POST
URL= str(urlList['url'])
URL= URL.strip('http://')
URL= "http://" + URL

recipe= __addRecipeUrl__(URL)

if (recipe == 'FailToOpenURL') or (recipe == 'Invalid-website-URL'):
#request.session["ErrorMsgURL"]= "Kindly check URL, Please enter a valid URL"
objc["ErrorMsgURL"]= "Kindly check URL, Please enter a valid URL"
print "here global_context =", objc
arurl= HttpResponseRedirect("/project/add/import/")
arurl['ErrorMsgURL']= objc["ErrorMsgURL"]
return (arurl)
else:
objc["recipe"] = recipe
return render_to_response('addRecipe.html',
objc,
context_instance = RequestContext(request))
except:
objc["recipe"] = ""
return render_to_response('addRecipe.html',
objc,
context_instance = RequestContext(request))
else:
login_redirect['next']= "/project/add/"
return HttpResponseRedirect("/project/login")

关于python - 在 django 开发服务器上工作,但不在 apache 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3021418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com