2017-02-03 1 views
0

私が作成したサブドメインでpythonファイルを実行しようとしています。 Hostgatorのによると、Pythonのファイルはサポートされていますが、ではない私は、ファイル全体で使用webapp2をフレームワーク、:ホスティング会社はWebApp2をサポートしていません - その場所で何が使えますか?

#!/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) 

私の知る限り理解し、Webアプリケーション/ webapp2をそれらの内部ハンドラ+の機能が動作するものです。たとえば、 "Username"ラベルにユーザ名を入力することは、webapp2で可能になります。

HostGatorはwebapp2をサポートしていないため、その代わりに他に何が使えますか?

http://webpy.org/install

https://pypi.python.org/pypi

しかし、私はこれらのパッケージのいずれかをインストールし、私はどのように、私のサブドメインのディレクトリにそのフォルダをコピーした後:Hostgatorののテクニカルサポート担当者は、私はPIPを使用するか、多分は、PyPI提案しましたファイルの先頭に使用するコマンドを知っている。私はちょうどなど、

import pip 

class MainHandler(pip.RequestHandler):

class TestHandler(pip.RequestHandler):を言うのですか?ここで

は私がホストしようとしているところです。

usersignup.thehamburgercollection.com

Link to previous question

UPDATE:私はappspot.com上でこのアプリ(Googleクラウド)をホストすることができませんでした。私はちょうど正しいディレクトリに私のファイルをアップロードする方法を把握できませんでした - 指示は明確ではなかった/ YouTubeのチュートリアルは古いです。方法を見つけたら、私は解決策を投稿します。

+3

'pip'は、Pythonライブラリをインストールするためのコマンドラインツールです。あなたのアプリケーションの一部となるものではありません。 – duskwuff

+0

webapp2が必要ですか? Google App Engineを見てみましょう。たぶんHeroku –

+0

@duskwuff WebPyのダウンロード/インストールについては、WebPyフォルダをサブドメインフォルダに配置した後、ファイル内で使用する「コマンド」を見つける必要があります。それがファイルで使用されている 'webapp2'の – Sean

答えて

0

あなたの質問は本当に混乱しています.PIPはパッケージマネージャーだけです.PIPはNPJとNodeJsの関係をPythonにしています。 Google Cloudにアプリをデプロイするのは簡単です。最初にGoogle Cloud SDkをインストールし、アプリケーションのルートディレクトリに移動してコマンドを実行します。

gcloud deploy 
関連する問題