Python: страница никогда не загружается, нет синтаксических ошибок

0

Я создал простую веб-страницу на Python, используя Jinja2. Когда я запускаю свой код в браузере, страница просто говорит о загрузке, но никогда не загружается. У меня установлен jinja2, и у меня есть файл front.html в папке шаблонов.

Мой журнал показывает:

WARNING  2014-02-21 14:17:49,151 api_server.py:341] Could not initialize images API; you are likely missing the Python "PIL" module.
INFO     2014-02-21 14:17:49,164 api_server.py:138] Starting API server at: http://localhost:49824
INFO     2014-02-21 14:17:49,168 dispatcher.py:171] Starting module "default" running at: http://localhost:11001
INFO     2014-02-21 14:17:49,171 admin_server.py:117] Starting admin server at: http://localhost:8004

Мой файл app.yaml:

application: ascii
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: .*
  script: asciichan.app
- url: /templates
  script: front.html

libraries:
- name: webapp2
  version: "2.5.2"
- name: jinja2
  version: latest

Мой файл Python:

import os
import webapp2
import jinja2

from google.appengine.ext import db

template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir),
                               autoescape = True)

class Handler(webapp2.RequestHandler):
    def write(self, *a, **kw):
        self.response.out.write(*a, **kw)

    def render_str(self, template, **params):
        t = jinja_env.get_template(template)
        return t.render(params)

    def render(self, template, **kw):
        self.write(self.render_str(template, **kw))

class MainPage(Handler):
    def render_front(self, title="", art="", error=""):
        self.render("front.html", title=title, art=art, error=error)

    def get(self):
        self.render_front()

    def post(self):
        title = self.request.get("title")
        art = self.request.get("art")

        if title and art:
            self.write("thanks!")
        else:
            error = "we need both a title and some artwork!"
            self.render_front(title, art, error)

app = webapp2.WSGIApplication([('/', MainPage)], debug = True)

Мой файл front.html:

<!DOCTYPE html>

<html>
    <head>
        <title>/ascii/</title>
    </head>

    <body>
        <h1>/ascii/</h1>

        <form method = "post">
            <label>
                <div>title</div>
                <input type="text" name="title" value="{{title}}">
            </label>

            <label>
                <div>art</div>
                <textarea name="art">{{art}}</textarea>
            </label>

            <div class="error">{{error}}</div>
            <input type="submit">
        </form>

    </body>
</html>

Извините, это так долго, но я смущен тем, что может быть проблемой. Любая помощь будет принята с благодарностью.

  • 0
    какой URL вы собираетесь?
  • 0
    Просто работает с моего локального хоста, пока нет конкретного URL.
Показать ещё 6 комментариев
Теги:
jinja2
app.yaml

1 ответ

0
Лучший ответ

Он говорит, что ваш сервер по умолчанию:

http://localhost:11001

INFO     2014-02-21 14:17:49,168 dispatcher.py:171] Starting module "default" running  at: http://localhost:11001 

Как бы то ни было:

http://localhost:11001/ 

потребует, чтобы у вас был индекс def в файле asciichan.py. Попробуйте это в своем браузере:

http://localhost:11001/MainPage 

Надеюсь это поможет!

  • 0
    Большое спасибо за вашу помощь, это работает!

Ещё вопросы

Сообщество Overcoder
Наверх
Меню