我是Python的新手,我正在尝试使用Python Anywhere运行web.py应用程序,但我一直收到No template named index
错误.我已修改wsgi.py
为使用以下内容:
import web
import MySQLdb
urls = (
'/', 'index'
)
render = web.template.render('/home/user/templates/')
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
我试图在pythonanywhere上部署我的django应用程序.
从apache错误日志回溯:
2013-07-23 09:31:35,058 :Internal Server Error: /favicon.ico
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 89, in get_response
response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py", line 55, in process_request
host = request.get_host()
File "/usr/local/lib/python2.7/dist-packages/django/http/__init__.py", line 179, in get_host
"Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): %s" % host)
SuspiciousOperation: Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): monty_singh.pythonanywhere.com
Run Code Online (Sandbox Code Playgroud)
我试过['*']
并['monty_singh.pythonanywhere.com']
作为值,ALLOWED_HOSTS
但应用程序仍然无法正常工作.无论我设置什么值,ALLOWED_HOSTS
我都会得到同样的错误.
我试图将我的pythonanywhere [hosting]帐户中的编辑推送到 GitHub上的原始主服务器并且失败.
它要求我的GitHub用户名和密码.并且它显示以下错误,尽管提供了正确的凭据:
remote: Anonymous access to akhyansh13/simplifier.git denied.
fatal: Authentication failed for 'https://www.github.com/akhyansh13/simplifier.git/'
Run Code Online (Sandbox Code Playgroud)
我怎么推?
我需要每天重新加载托管在pythonAnywhere上的 Flask 应用程序。是否可以使用我已有的代码自动重新加载应用程序?
该应用程序是一个简单的天数计数器:
import datetime
from flask import Flask, render_template
app = Flask(__name__)
wsgi_app = app.wsgi_app
currentDate = datetime.date.today()
userInput = '07/22/2015'
targetdate = datetime.datetime.strptime(userInput, '%m/%d/%Y').date()
calc = targetdate - currentDate
msg=str(calc.days)
@app.route('/', methods=['GET','POST'])
def index():
return render_template('index.html', message=msg)
Run Code Online (Sandbox Code Playgroud)
我已经浏览过: 此链接到 pythonAnywhere 论坛,但它是一个我必须部署在我的电脑上而不是应用程序本身上的脚本。
问:如何每天自动重新加载应用程序?有什么方法可以使用网站上的计划功能来执行相同的操作吗?
(Django版本1.9,Python版本3.4.3,使用虚拟环境制作 mkvirtualenv --python=/usr/bin/python3.4 django19
)
我一直非常密切地关注Django教程,直到第5部分没有任何问题:
https://docs.djangoproject.com/en/1.9/intro/tutorial05/
虽然严格来说,问题与第5部分无关,但请耐心等待.我正在遵循pythonanywhere框架中的教程,因为最终我想在那里托管一个网站.因此,我也在关注pythonanywhere提供的"关注Django教程":
https://help.pythonanywhere.com/pages/FollowingTheDjangoTutorial
虽然在教程的第5部分的建议中没有预料到我的问题.现在问题 - 在Django教程中的重点是:
要检查错误是否确实存在,请使用Admin创建一个日期位于将来的问题,并使用shell检查方法
在链接到shell之后,我尝试(按照链接中的指示)运行:
django-admin shell --plain
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误消息
(django19)19:11 ~/mysite $ django-admin shell --plain
Traceback (most recent call last):
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/core/management/base.py", line 391, in execute saved_locale = translation.get_language()
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 176, in get_language
return _trans.get_language()
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 57, in __getattr__
if settings.USE_I18N:
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/home/me/.virtualenvs/django19/lib/python3.4/site-packages/django/conf/__init__.py", line 41, in _setup
% (desc, ENVIRONMENT_VARIABLE)) …
Run Code Online (Sandbox Code Playgroud) 我遵循了 DjangoGirls 教程,并在本地设置上创建了一个博客。我使用了 SQLite3 数据库,因为这是 Django 教程建议的默认数据库。我的本地 SQLite3 数据库有几个帖子。我在 pythonanywhere.com 上推送了我的代码。现在,我的本地数据库与在线数据库不同步,我的意思是我的帖子在互联网上看不到。我设法在 pythonanywhere.com 上创建了一个 blog_data.dmp 数据库转储,但无法在 pythonanywhere 上访问它。有人可以帮我吗? 在此处输入图片说明 非常感谢!
我最近在 PythonAnywhere 开设了一个帐户,并了解到它是一个在线 IDE 和 Web 托管服务,但作为 python 3.4 的初学者,我到底可以用它做什么?
所以我想在 pythonanywhere 上部署我的网站。我创建了 virtualenv,安装了 Django 以及我网站所需的所有应用程序。我创建了新应用程序并将其与我从 GitHub 克隆的项目相关联。这是我的网络应用程序中设置的屏幕截图:
我的项目结构如下所示:
我的设置.py
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ADMIN_ENABLED = False
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions', …
Run Code Online (Sandbox Code Playgroud) 这是我使用Flask和Python的第一个应用程序.
我使用以下URL格式从Arduino发送POST请求到在Pythonanywhere服务器实例上运行的烧瓶应用程序.
有效的POST请求:3个URL参数 http://voyagers.pythonanywhere.com/senddata?node=1234&lat=18.5580&lng=73.8075
我需要通过以某种形式验证URL来阻止进一步处理的请求.我希望这可以保护我的应用程序免受未经身份验证的POST请求.
说这样的话:超过3个URL参数 http://voyagers.pythonanywhere.com/senddata?node=324&lat=18.5580&lng=73.8075&a=c&a=d
我怎样才能在Flask中实现这一目标?
还建议,如果有更好的方法可以用于保护未授权请求的应用程序.
我在 python 上的任何地方都有一个文件结构:
烧瓶主机(文件夹),其中包含:
app.py 包含 -:
import flask
from flask import request, jsonify
import sqlite3
app = flask.Flask(__name__)
app.config["DEBUG"] = True
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
@app.route('/', methods=['GET'])
def home():
return '''<h1>Distant Reading Archive</h1>
<p>A prototype API for distant reading of science fiction novels.</p>'''
@app.route('/api/v1/resources/books/all', methods=['GET'])
def api_all():
conn = sqlite3.connect('books.db')
conn.row_factory = dict_factory
cur = conn.cursor()
all_books = cur.execute('SELECT * FROM books;').fetchall()
return jsonify(all_books)
@app.errorhandler(404) …
Run Code Online (Sandbox Code Playgroud) pythonanywhere ×10
python ×7
django ×4
flask ×3
sqlite ×2
apache ×1
django-admin ×1
git ×1
github ×1
http-post ×1
python-3.x ×1
reload ×1
url ×1
web.py ×1