我現在面臨的問題與全局變量,當我在它工作正常Django開發服務器運行的不是工作,而是在Apache中這是行不通的蟒蛇全局變量阿帕奇
這裏是下面的代碼:
red= "/project3/test/"
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("/project3/add/import/")
arurl['ErrorMsgURL']= objc["ErrorMsgURL"]
#return HttpResponseRedirect("/project3/add/import/")
#return render_to_response('addRecipeUrl.html', objc, context_instance = RequestContext(request))
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:
global red
red= "/project3/add/"
return HttpResponseRedirect("/project3/login")
def showAddRecipeUrl(request):
if "userid" in request.session:
return render_to_response('addRecipeUrl.html',
objc,
context_instance = RequestContext(request))
else:
global red
red= "/project3/add/import/"
return HttpResponseRedirect("/project3/login")
def showLogin(request):
obj = {}
obj["error_message"] = ""
obj["registered"] = ""
if request.method == "POST":
if (red == "/project3/test"):
next= '/project3/recipes'
else:
next= red
try:
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
except:
user = authenticate(request=request)
if user is not None:
if user.is_active:
login(request, user)
request.session["userid"] = user.id
# Redirect to a success page.
return HttpResponseRedirect(next)
這個代碼在Django開發服務器很好,但在Apache中的URL是被重定向到/項目3 /食譜「
如果您在函數中查看全局變量'red'的值是在用戶會話過期或未登錄之後設置的,但正在嘗試訪問內部URL,那麼我將得到全局變量red的正確值,即當用戶在django開發服務器上運行時,用戶試圖訪問的url而無需登錄,但相同的代碼在apache服務器上無法運行。 – Suhail 2010-06-14 08:12:02