我正在尝试使用Apache和mod_wsgi运行Bottle.py.
我在Windows上运行它,使用xampp.python v2.7
我在httpd中的Apache配置:
<VirtualHost *>
ServerName example.com
WSGIScriptAlias / C:\xampp\htdocs\GetXPathsProject\app.wsgi
<Directory C:\xampp\htdocs\GetXPathsProject>
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
我的app.wsgi代码:
import os
os.chdir(os.path.dirname(__file__))
import bottle
application = bottle.default_app()
Run Code Online (Sandbox Code Playgroud)
我的hello.py:
from bottle import route
@route('/hello')
def hello():
return "Hello World!"
Run Code Online (Sandbox Code Playgroud)
当我去的时候,localhost/hello
我收到404错误.我在Apache日志文件中没有任何其他错误,可能缺少基本的东西.
我正在使用Flask,Flask-Babel和Jinja2.我正在尝试生成.pot文件.那就是我到目前为止所做的.
我的babel.cfg看起来像这样:
[python: **.py]
[jinja2: **.html]
encoding = utf-8
extensions=jinja2.ext.autoescape,jinja2.ext.with_
Run Code Online (Sandbox Code Playgroud)
我用我的应用程序初始化Flask-Babel,如下所示:
# Babel init
babel = Babel(app)
app.config['BABEL_DEFAULT_LOCALE'] = 'en'
Run Code Online (Sandbox Code Playgroud)
在我的模板目录中,我有homepage.html:
...
<div class="news-wrapper">
<p class="quote">{{ gettext('Hey there') }}</p>
<p class="quote">{% trans %}Trying 42{% endtrans %}</p>
<p class="quote">{{ _('Maybe like this?') }}</p>
</div>
...
Run Code Online (Sandbox Code Playgroud)
然后运行这个命令(当我在我的virtualenv时):
pybabel extract -F babel.cfg -o messages.pot .
Run Code Online (Sandbox Code Playgroud)
其中一条输出线是:
extracting messages from templates/homepage.html (extensions="jinja2.ext.autoescape,jinja2.ext.with_", encoding="utf-8")
Run Code Online (Sandbox Code Playgroud)
它会生成一个包含以下内容的messages.pot文件:
# Translations template for PROJECT.
# Copyright (C) 2015 ORGANIZATION
# This file is distributed under the same license as …
Run Code Online (Sandbox Code Playgroud) 我正在尝试从ANTLR开始。当我导入模块时antlr
它工作得很好,但是如果我尝试导入MyGrammarLexer和MyGrammarParser,它表明 MyGrammarLexer 和 Parser 不在 lib 中。我使用 PyCharm ,安装了 ANTLR: pip3 install antlr4-python3-runtime我的代码是:
import sys
from antlr4 import *
import MyGrammarLexer
import MyGrammarParser
def main(argv):
input = FileStream(argv[1])
lexer = MyGrammarLexer(input)
stream = CommonTokenStream(lexer)
parser = MyGrammarParser(stream)
tree = parser.startRule()
if __name__ == '__main__':
main(sys.argv)
Run Code Online (Sandbox Code Playgroud)
也许谁知道为什么我无法导入 MyGrammarLexer 和 MyGrammarParser?请建议!反击:
/usr/bin/python3.6 /home/andrejka/PycharmProjects/Parser/parser.py
Traceback (most recent call last):
File "/home/andrejka/PycharmProjects/Parser/parser.py", line 2, in <module>
from antlr4 import *
File "/usr/lib/python3/dist-packages/antlr4/__init__.py", line 5, in <module> …
Run Code Online (Sandbox Code Playgroud)