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

标签 python django apache url

我遇到了 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/

相关文章:

python - makemigrations 在 Django 1.9 中因 django_enumfield 失败

php - 在 linux apache 上运行 Drupal 时内存泄漏,但相同的应用程序不会在 windows 服务器上泄漏内存

python - 从字符串格式到整数?

python - 如何在 selenium,python 中处理 TimeoutException

python - Django/Python 世界中是否有与 WordPress 的 SimplePie 插件等效的东西?

带有负载平衡器的 apache2 忽略服务器

regex - 阻止访问以 ~ 开头的文件夹及其所有文件夹/文件

python - 将句子转换为 pig 拉丁语?

python - 使用 PIL 缓冲到图像

Django SMTP 身份验证最佳实践