托管公司不支持WebApp2-我可以代替它使用什么? [英] Hosting Company Doesn't Support WebApp2 - What Can I Use In Its Place?

查看:80
本文介绍了托管公司不支持WebApp2-我可以代替它使用什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我创建的子域上运行python文件.根据HostGator的说法,支持python文件,但不支持webapp2框架,我在整个文件中都使用了该框架:

I'm trying to run a python file on a subdomain that I created. According to HostGator, python files are supported, but not the webapp2 framework, which I used throughout the file:

#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.

# See the License for the specific language governing permissions and
# limitations under the License.
#

import webapp2
import cgi

def Build_Page(textarea_content):

form = """
<table>
    <tr>
    <td>
    <label>{0}</label>
    </td>
    <td>
    <label>Username: <input type="text" name="username"/></label>
    </td>
    </tr>

    <tr>
    <td>
    <label>{1}</label>
    </td>
    <td>
    <label>Password: <input type="text" name="password"/></label>
    </td></tr>

    <tr>
    <td> 
    <label>{2}</label>
    </td>
    <td>
    <label>Verify Password: <input type="text" name="verify_password"/>
    </label>
    </td>
    </tr>

    <tr>
    <td>
    <label>{3}</label>
    </td>
    <td>
    <label>Email (optional): <input type="text" name="email"/></label>
    </td>
    </tr>

</table>
"""
submit = "<input type = 'submit'/>"
form2 = ("<form method='post'>" + form + submit + "
</form>").format("Please enter a username",
"Please enter a password", "Passwords must match","Please enter a valid
email")

header = "<h1>User Signup</h1>" 

return header + form2

class MainHandler(webapp2.RequestHandler):
    def get(self):
        content = Build_Page("")
        self.response.write(content)

    def post(self):
    # look inside the request to figure out what the user typed
        username = self.request.get("username")
        password = self.request.get("password")
        verify_password = self.request.get("verify_password")
        email = self.request.get("email")
    # if the user typed nothing at all, redirect
        if (not username) or (username.strip() == ""):
            error = "Please enter a username."
            self.response.write(error)
            self.redirect("/?error=" + cgi.escape(error, quote=True))

        if (not password) or (username.strip() == ""):
            error = "Please enter a username."
            self.response.write(error)
            self.redirect("/?error=" + cgi.escape(error, quote=True))

        """if (not username) or (username.strip() == ""):
            error = "Please enter a username."
            self.response.write(error)
            self.redirect("/?error=" + cgi.escape(error, quote=True))

        if (not username) or (username.strip() == ""):
            error = "Please enter a username."
            self.response.write(error)
            self.redirect("/?error=" + cgi.escape(error,
            quote=True))"""

    #self.write.form2    
    #message = self.request.get("message") # hello</textarea>hello
    #rotation = int(self.request.get("rotation")) # 0 
    #encrypted_message = caesar.encrypt(message, rotation) 
    #hello</textarea>hello
    #escaped_message = cgi.escape(encrypted_message) 
    # hello&lt;/textarea&gt;hello
    #content = build_page(escaped_message)
    #self.response.write(content)

    #original_form = form.format("","","","","","")
    #page footer

    #class TestHandler(webapp2.RequestHandler):
    #    """ Handles requests coming in to '/add'
    #        e.g. www.user-signup.com/add
    #    """
    #    def get(self):

app = webapp2.WSGIApplication([
    ('/', MainHandler),
    #('/', TestHandler)
], debug=True)

据我了解,webapp/webapp2是使Handlers及其内部功能正常工作的原因.例如,通过webapp2可以在用户名"标签中获取用户名输入.

As far as I understand, webapp / webapp2 is what makes the Handlers + the functions inside of them work. Getting the username input in the "Username" label, for example, is made possible with webapp2.

由于HostGator不支持webapp2,我还可以使用它做什么呢? HostGator的技术支持人员建议我使用PIP或PyPI:

Since HostGator doesn't support webapp2, what else can I use in its place? The technical support person at HostGator suggested I use PIP or maybe PyPI:

http://webpy.org/install

https://pypi.python.org/pypi

但是,在我安装了这些软件包之一并将其文件夹复制到我的子域的目录之后,我如何知道在文件顶部使用什么命令.我只是说

But after I install one of these packages and copy its folder to the directory for my subdomain, how do I know what command to use at the top of the file. Do I just say

import pip

class MainHandler(pip.RequestHandler):

class TestHandler(pip.RequestHandler):,等等?

我要在这里托管:

usersignup.thehamburgercollection.com

链接到上一个问题

更新:我无法在appspot.com(Google云)上托管此应用.我只是不知道如何将文件上传到正确的目录-说明不明确/YouTube教程已过时.如果/当我知道如何解决时,我将发布解决方案.

UPDATE: I wasn't able to host this app on appspot.com (google cloud). I just could not figure out how to upload my files to the correct directory - the instructions weren't clear / youtube tutorials were out of date. I'll post a solution if / when I figure out how.

推荐答案

您的问题确实令人困惑,PIP只是一个程序包管理器,PIP是python,NPM是NodeJ.将应用程序部署到Google Cloud很简单.首先安装 Google Cloud SDk 并导航到应用程序的根目录并运行命令.

Your question is really confusing, PIP is just a package manager, PIP is to python what NPM is to NodeJs. Deploying apps to Google Cloud is straightforward. First Install Google Cloud SDk and navigate to your application's root directory and run the command.

gcloud deploy

这篇关于托管公司不支持WebApp2-我可以代替它使用什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆