2010-06-11 56 views
1

我面臨的問題與Apache服務器,我們已經編寫的代碼,其中如果在表單字段中輸入的URL是有效的,它會顯示錯誤消息,當我運行代碼通過django開發服務器它工作正常,顯示錯誤信息,但是當通過apache運行時,則不顯示錯誤消息只是返回到該頁面本身。這裏是下面的蟒蛇和HTML兩者的代碼:工作在Django的開發服務器上,但不是在Apache上


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的工作開發服務器。

謝謝 Suhail

+1

爲什麼使用「全局」?字典「objc」可以在你的(通過醜陋的雙下劃線)方法訪問。 – zovision 2010-06-11 08:52:30

+1

你在apache下的應用程序作爲wsgi,proxy,mode_python的部署方法嗎? 請參閱apache錯誤日誌。 請勿使用打印進行調試。 除嘗試塊外,不要使用空白。你的代碼可能會像KeyError和其他人一樣在嘗試中產生異常 – estin 2010-06-11 09:04:30

+1

而且你應該明確考慮使用django.forms,所以你不需要手動完成所有這些工作。如果你喜歡,URLField可以自動檢查正確的URL。請閱讀表格文檔:http://docs.djangoproject.com/en/1.2/#forms – mawimawi 2010-06-11 09:09:47

回答

1

嘿,夥計們,感謝您的支持,問題解決了,我就是這麼做的。

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") 
相關問題