我正在尝试部署到heroku,但是它对我不起作用,我遇到了错误。请帮助web开发新手。我不知道缺少了什么,我正确地做了heroku部分,那里没有任何缺失。我有一个require.txt和runtime.txt以及包含home.html和price.html
的模板文件夹文件结构
├── app.py
├── requirments.txt
├── templates
├── home.html
├── price.html
├── _formhelper.html
我遇到此错误
heroku logs -t
2018-11-06T15:43:31.156171+00:00 heroku[web.1]: State changed from starting to up
2018-11-06T15:43:32.309587+00:00 app[web.1]: [2018-11-06 15:43:32 +0000] [10] [ERROR] Exception in worker process
2018-11-06T15:43:32.309607+00:00 app[web.1]: Traceback (most recent call last):
2018-11-06T15:43:32.309609+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2018-11-06T15:43:32.309611+00:00 app[web.1]: worker.init_process()
2018-11-06T15:43:32.309613+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
2018-11-06T15:43:32.309614+00:00 app[web.1]: self.load_wsgi()
2018-11-06T15:43:32.309616+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2018-11-06T15:43:32.309618+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2018-11-06T15:43:32.309620+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2018-11-06T15:43:32.309622+00:00 app[web.1]: self.callable = self.load()
2018-11-06T15:43:32.309623+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2018-11-06T15:43:32.309625+00:00 app[web.1]: return self.load_wsgiapp()
2018-11-06T15:43:32.309626+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2018-11-06T15:43:32.309628+00:00 app[web.1]: return util.import_app(self.app_uri)
2018-11-06T15:43:32.309629+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
2018-11-06T15:43:32.309631+00:00 app[web.1]: __import__(module)
2018-11-06T15:43:32.309633+00:00 app[web.1]: File "/app/app.py", line 73, in <module>
2018-11-06T15:43:32.309634+00:00 app[web.1]: render = web.template.render('templates/')
2018-11-06T15:43:32.309636+00:00 app[web.1]: NameError: name 'web' is not defined
2018-11-06T15:43:32.309846+00:00 app[web.1]: [2018-11-06 15:43:32 +0000] [10] [INFO] Worker exiting (pid: 10)
2018-11-06T15:43:32.323281+00:00 app[web.1]: [2018-11-06 15:43:32 +0000] [11] [ERROR] Exception in worker process
2018-11-06T15:43:32.323285+00:00 app[web.1]: Traceback (most recent call last):
2018-11-06T15:43:32.323287+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2018-11-06T15:43:32.323290+00:00 app[web.1]: worker.init_process()
2018-11-06T15:43:32.323291+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
2018-11-06T15:43:32.323293+00:00 app[web.1]: self.load_wsgi()
2018-11-06T15:43:32.323294+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2018-11-06T15:43:32.323296+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2018-11-06T15:43:32.323298+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
2018-11-06T15:43:32.323300+00:00 app[web.1]: self.callable = self.load()
2018-11-06T15:43:32.323302+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2018-11-06T15:43:32.323303+00:00 app[web.1]: return self.load_wsgiapp()
2018-11-06T15:43:32.323305+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2018-11-06T15:43:32.323307+00:00 app[web.1]: return util.import_app(self.app_uri)
2018-11-06T15:43:32.323309+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
2018-11-06T15:43:32.323311+00:00 app[web.1]: __import__(module)
2018-11-06T15:43:32.323312+00:00 app[web.1]: File "/app/app.py", line 73, in <module>
2018-11-06T15:43:32.323314+00:00 app[web.1]: render = web.template.render('templates/')
2018-11-06T15:43:32.323316+00:00 app[web.1]: NameError: name 'web' is not defined
2018-11-06T15:43:32.323636+00:00 app[web.1]: [2018-11-06 15:43:32 +0000] [11] [INFO] Worker exiting (pid: 11)
2018-11-06T15:43:32.504903+00:00 app[web.1]: [2018-11-06 15:43:32 +0000] [4] [INFO] Shutting down: Master
2018-11-06T15:43:32.505706+00:00 app[web.1]: [2018-11-06 15:43:32 +0000] [4] [INFO] Reason: Worker failed to boot.
2018-11-06T15:43:32.622429+00:00 heroku[web.1]: Process exited with status 3
2018-11-06T15:43:32.638459+00:00 heroku[web.1]: State changed from up to crashed
2018-11-06T15:43:33.000000+00:00 app[api]: Build succeeded
2018-11-06T15:45:06.501054+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=stockprofile.herokuapp.com request_id=4ae940e6-63df-4111-9c63-d8919c73b7d2 fwd="24.4.212.103" dyno= connect= service= status=503 bytes= protocol=https
2018-11-06T16:06:27.000000+00:00 app[api]: Build started by user ezana.tesfaye@sjsu.edu
2018-11-06T16:07:00.130149+00:00 app[api]: Release v10 created by user ezana.tesfaye@sjsu.edu
2018-11-06T16:07:00.545553+00:00 heroku[web.1]: State changed from crashed to starting
2018-11-06T16:07:00.130149+00:00 app[api]: Deploy c3a67933 by user ezana.tesfaye@sjsu.edu
2018-11-06T16:07:09.047923+00:00 heroku[web.1]: Starting process with command `gunicorn app:app`
2018-11-06T16:07:11.829909+00:00 app[web.1]: [2018-11-06 16:07:11 +0000] [4] [INFO] Starting gunicorn 19.9.0
2018-11-06T16:07:11.830597+00:00 app[web.1]: [2018-11-06 16:07:11 +0000] [4] [INFO] Listening at: http://0.0.0.0:23949 (4)
2018-11-06T16:07:11.830720+00:00 app[web.1]: [2018-11-06 16:07:11 +0000] [4] [INFO] Using worker: sync
2018-11-06T16:07:11.835287+00:00 app[web.1]: [2018-11-06 16:07:11 +0000] [10] [INFO] Booting worker with pid: 10
2018-11-06T16:07:11.879158+00:00 app[web.1]: [2018-11-06 16:07:11 +0000] [11] [INFO] Booting worker with pid: 11
2018-11-06T16:07:12.801670+00:00 heroku[web.1]: State changed from starting to up
2018-11-06T16:07:16.000000+00:00 app[api]: Build succeeded
2018-11-06T16:07:29.324330+00:00 app[web.1]: /app/app.py:44: FlaskWTFDeprecationWarning: "flask_wtf.Form" has been renamed to "FlaskForm" and will be removed in 1.0.
2018-11-06T16:07:29.324347+00:00 app[web.1]: form=investmentForm()
2018-11-06T16:07:29.327192+00:00 app[web.1]: [2018-11-06 16:07:29,325] ERROR in app: Exception on / [GET]
2018-11-06T16:07:29.327196+00:00 app[web.1]: Traceback (most recent call last):
2018-11-06T16:07:29.327198+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
2018-11-06T16:07:29.327199+00:00 app[web.1]: response = self.full_dispatch_request()
2018-11-06T16:07:29.327202+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
2018-11-06T16:07:29.327203+00:00 app[web.1]: rv = self.handle_user_exception(e)
2018-11-06T16:07:29.327205+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
2018-11-06T16:07:29.327206+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2018-11-06T16:07:29.327208+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
2018-11-06T16:07:29.327210+00:00 app[web.1]: raise value
2018-11-06T16:07:29.327211+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
2018-11-06T16:07:29.327213+00:00 app[web.1]: rv = self.dispatch_request()
2018-11-06T16:07:29.327214+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
2018-11-06T16:07:29.327216+00:00 app[web.1]: return self.view_functions[rule.endpoint](**req.view_args)
2018-11-06T16:07:29.327217+00:00 app[web.1]: File "/app/app.py", line 68, in index
2018-11-06T16:07:29.327219+00:00 app[web.1]: return render_template('home.html',form=form)
2018-11-06T16:07:29.327220+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/templating.py", line 134, in render_template
2018-11-06T16:07:29.327222+00:00 app[web.1]: return _render(ctx.app.jinja_env.get_or_select_template(template_name_or_list),
2018-11-06T16:07:29.327224+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/jinja2/environment.py", line 869, in get_or_select_template
2018-11-06T16:07:29.327226+00:00 app[web.1]: return self.get_template(template_name_or_list, parent, globals)
2018-11-06T16:07:29.327228+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/jinja2/environment.py", line 830, in get_template
2018-11-06T16:07:29.327229+00:00 app[web.1]: return self._load_template(name, self.make_globals(globals))
2018-11-06T16:07:29.327231+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/jinja2/environment.py", line 804, in _load_template
2018-11-06T16:07:29.327232+00:00 app[web.1]: template = self.loader.load(self, name, globals)
2018-11-06T16:07:29.327234+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/jinja2/loaders.py", line 113, in load
2018-11-06T16:07:29.327235+00:00 app[web.1]: source, filename, uptodate = self.get_source(environment, name)
2018-11-06T16:07:29.327237+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/templating.py", line 58, in get_source
2018-11-06T16:07:29.327238+00:00 app[web.1]: return self._get_source_fast(environment, template)
2018-11-06T16:07:29.327240+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.7/site-packages/flask/templating.py", line 86, in _get_source_fast
2018-11-06T16:07:29.327242+00:00 app[web.1]: raise TemplateNotFound(template)
2018-11-06T16:07:29.327248+00:00 app[web.1]: jinja2.exceptions.TemplateNotFound: home.html
2018-11-06T16:07:29.328028+00:00 app[web.1]: 10.164.78.142 - - [06/Nov/2018:16:07:29 +0000] "GET / HTTP/1.1" 500 291 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"
2018-11-06T16:07:29.328715+00:00 heroku[router]: at=info method=GET path="/" host=stockprofile.herokuapp.com request_id=3bf5ddb1-a7c0-4eed-9842-2a2f646dd84d fwd="24.4.212.103" dyno=web.1 connect=1ms service=5ms status=500 bytes=456 protocol=https
requirments.txt
alpha-vantage==2.1.0
arrow==0.12.1
astroid==2.0.4
awscli==1.16.48
awsebcli==3.14.6
blessed==1.15.0
botocore==1.12.38
cached-property==1.5.1
cement==2.8.2
certifi==2018.10.15
chardet==3.0.4
Click==7.0
colorama==0.3.9
dateparser==0.7.0
docker==3.5.1
docker-compose==1.21.2
docker-pycreds==0.3.0
dockerpty==0.4.1
docopt==0.6.2
docutils==0.14
dominate==2.3.4
Flask==1.0.2
Flask-Bootstrap==3.3.7.1
Flask-WTF==0.14.2
gunicorn==19.9.0
idna==2.6
iexfinance==0.3.4
isort==4.3.4
itsdangerous==1.1.0
Jinja2==2.10
jmespath==0.9.3
jsonschema==2.6.0
lazy-object-proxy==1.3.1
MarkupSafe==1.0
mccabe==0.6.1
moment==0.8.2
numpy==1.15.4
pandas==0.23.4
pathspec==0.5.5
pyasn1==0.4.4
pylint==2.1.1
python-dateutil==2.7.5
pytz==2018.7
PyYAML==3.13
regex==2018.11.3
requests==2.18.4
rsa==3.4.2
s3transfer==0.1.13
semantic-version==2.5.0
six==1.11.0
termcolor==1.1.0
texttable==0.9.1
times==0.7
tzlocal==1.5.1
urllib3==1.22
visitor==0.1.3
wcwidth==0.1.7
websocket-client==0.54.0
Werkzeug==0.14.1
wrapt==1.10.11
WTForms==2.2.1
runtime.txt
python-3.7.0
这是我的Procfile
web: gunicorn app:app
这是我的app.py文件
from flask import
Flask,render_template,flash,redirect,request
import requests
from flask_wtf import Form
from wtforms import StringField,PasswordField,FloatField,SubmitField
from wtforms.validators import InputRequired,Email,Length,AnyOf
from flask_bootstrap import Bootstrap
app=Flask(__name__)
Bootstrap(app)
app.config['SECRET_KEY']='strongPass'
class investmentForm(Form):
stockSymbol=StringField('Ticket Symbol',validators= .
[InputRequired(),Length(min=2,max=5,message='Please Enter Correct
symbol')])
allotment=FloatField('Allotment',validators=[InputRequired()])
finalSharePrice=FloatField('Final Share Price',validators= .
[InputRequired()])
sellCommision=FloatField('Sell Commision',validators= .
[InputRequired()])
initialSharePrice=FloatField('Initial Share Price',validators= .
[InputRequired()])
buyCommission=FloatField('Buy Commission',validators= .
[InputRequired()])
taxGain=FloatField('Capital Gain Tax Rate (%)',validators= .
[InputRequired()])
submit=SubmitField()
def proceeds(allt,fSP):
return float(allt * fSP)
def cost(pcee,allt,iSP,sCommss,bCommss,taxCP):
#Calculate cost
comissions=sCommss+bCommss
calc=allt * iSP + comissions
n=pcee-calc
taxCP=(15/100) * n
return float(calc+taxCP)
def returnOnInvestment(netProfit, cost):
return (100+(netProfit-cost)/cost*100)
def calcBreakEven(iSP, allt, bCommss, sCommss):
return float((bCommss + sCommss) / allt + iSP)
@app.route("/",methods=['GET','POST'])
def index():
form=investmentForm()
if request.method== 'POST' and form.validate():
#Get form field data
symb=form.stockSymbol.data
allotment=form.allotment.data
sellCommision=form.sellCommision.data
finalSharePrice=form.finalSharePrice.data
initialSharePrice=form.initialSharePrice.data
buyCommission=form.buyCommission.data
taxGain=form.taxGain.data
#Calculate Proceeds
calcProceeds=proceeds(allotment,finalSharePrice)
#Calculate Net Cost
calcCost=cost(calcProceeds,allotment,initialSharePrice,sellCommision,buyCommission,taxGain)
#Raw Profit
netProfit=calcProceeds-calcCost
#Breakeven
calcBreakE=calcBreakEven(initialSharePrice,allotment,buyCommission,sellCommision)
#Return on investement
calcReturn=returnOnInvestment(netProfit,calcCost)
return render_template('price.html',form=form,calcProceeds=calcProceeds,calcCost=calcCost,netProfit=netProfit,calcBreakE=calcBreakE,calcReturn=calcReturn)
return render_template('home.html',form=form)
if __name__=='__main__':
app.run(debug=True)
price.html
{% extends 'bootstrap/base.html' %}
{% import 'bootstrap/wtf.html' as wtf%}
{% block title %}
Calculations
{% endblock %}
{% block content %}
<div class="container">
<h1 class="text-center">Profit Report</h1>
<div class="list-group text-center">
<a class="list-group-item list-group-item-action flex-column align-items-start ">
<div class="d-flex w-100 justify-content-between">
<h2 class="mb-1">Proceeds</h2>
<h5>ALLOTMENT * FINAL SHARE PRICE </h5>
</div>
<h1 class="text-center">$ {{ calcProceeds }}</h1>
<h1>{{ symb }}</h1>
</a>
<a class="list-group-item list-group-item-action flex-column align-items-start ">
<div class="d-flex w-100 justify-content-between">
<h2 class="mb-1">Cost</h2>
<h5>ALLOTMENT x INITIAL SHARE PRICE + COMMISIONS + TAX ON CAPITAL GAIN(%)</h5>
</div>
<h1 class="text-center color">$ {{ calcCost }}</h1>
</a>
<a class="list-group-item list-group-item-action flex-column align-items-start ">
<div class="d-flex w-100 justify-content-between">
<h2 class="mb-1">Net Profit</h2>
<h5>Proceeds - Cost</h5>
</div>
<h1 class="text-center">$ {{ netProfit }}</h1>
</a>
<a class="list-group-item list-group-item-action flex-column align-items-start ">
<div class="d-flex w-100 justify-content-between">
<h2 class="mb-1">Return on Investment </h2>
<h5>100+ NET PROFIT -COST /COST *100</h5>
</div>
<h1 class="text-center"> {{ calcReturn }}%</h1>
</a>
<a class="list-group-item list-group-item-action flex-column align-items-start ">
<div class="d-flex w-100 justify-content-between">
<h2 class="mb-1">Return on Investment </h2>
<h5>COMMISIONS / ALLOTMENT + INITIAL SHARE PRICE</h5>
</div>
<h1 class="text-center"> $ {{ calcBreakE }}</h1>
</a>
</div>
</div>
{% endblock %}
home.html
{% extends 'bootstrap/base.html' %}
{% import 'bootstrap/wtf.html' as wtf%}
{% block title %}
Stock Profit Calculator
{% endblock %}
{% block content %}
<div class="container">
<form method="POST" action="/">
<d1>
<h1 style='background:lightblue' class="jumbotron text-center">Calculate Your Stocks</h1>
{{wtf.quick_form(form)}}
</d1>
</form>
</div>
{% endblock %}
答案 0 :(得分:0)
问题是服务器由于某种原因无法识别“ templates”文件夹,因此我在应用程序init中指定了该文件
app = Flask(__name__, template_folder='templates')