flask 处理css文件问题

flask版本使用0.10版本。
文件结构:
/price
price.py
/templates
layout.html
index.html
rate.html
/static
style.css
这是我的python代码:
#-*-coding:utf-8-*-
fromflaskimportFlask,render_template
app=Flask(__name__)app.config.from_object(__name__)
app.config.from_envvar('FLASKR_SETTINGS',silent=True)
app.config.update(
#DATABASE='/flaskr.db',
DEBUG=True,
SECRET_KEY='freightprice',
USERNAME='admin',
PASSWORD='Jake'
)
@app.route("/")
defindex():
returnrender_template('index.html',page="index")
@app.route('/rate')
defrate():
returnrender_template('rate.html',page="rate")
@app.route('/update')
defupdate():
returnrender_template('update.html',page="update")
if__name__=='__main__':
app.run()
layout.html代码
HyunYoung|{{page}}
{%blockbody%}{%endblock%}
访问CSS的时候出现以下错误:
UnicodeDecodeErrorUnicodeDecodeError:'ascii'codeccan'tdecodebyte0xceinposition3:ordinalnotinrange(128)
Traceback(mostrecentcalllast)
File"C:\Python27\lib\site-packages\flask\app.py",line1836,in__call__returnself.wsgi_app(environ,start_response)
File"C:\Python27\lib\site-packages\flask\app.py",line1820,inwsgi_appresponse=self.make_response(self.handle_exception(e))
File"C:\Python27\lib\site-packages\flask\app.py",line1403,inhandle_exceptionreraise(exc_type,exc_value,tb)
File"C:\Python27\lib\site-packages\flask\app.py",line1817,inwsgi_appresponse=self.full_dispatch_request()
File"C:\Python27\lib\site-packages\flask\app.py",line1477,infull_dispatch_requestrv=self.handle_user_exception(e)
File"C:\Python27\lib\site-packages\flask\app.py",line1381,inhandle_user_exceptionreraise(exc_type,exc_value,tb)
File"C:\Python27\lib\site-packages\flask\app.py",line1475,infull_dispatch_requestrv=self.dispatch_request()
File"C:\Python27\lib\site-packages\flask\app.py",line1461,indispatch_requestreturnself.view_functions[rule.endpoint](**req.view_args)
File"C:\Python27\lib\site-packages\flask\helpers.py",line822,insend_static_filecache_timeout=cache_timeout)
File"C:\Python27\lib\site-packages\flask\helpers.py",line612,insend_from_directoryfilename=safe_join(directory,filename)
File"C:\Python27\lib\site-packages\flask\helpers.py",line582,insafe_joinreturnos.path.join(directory,filename)
File"C:\Python27\lib\ntpath.py",line108,injoinpath+="\\"+b
UnicodeDecodeError:'ascii'codeccan'tdecodebyte0xceinposition
3:ordinalnotinrange(128)Thedebuggercaughtanexceptioninyour
WSGIapplication.Youcannowlookatthetracebackwhichledtothe
error.Toswitchbetweentheinteractivetracebackandtheplaintext
one,youcanclickonthe"Traceback"headline.Fromthetext
tracebackyoucanalsocreateapasteofit.Forcodeexecution
mouse-overtheframeyouwanttodebugandclickontheconsoleicon
ontherightside.
YoucanexecutearbitraryPythoncodeinthestackframesandtherearesomeextrahelpersavailableforintrospection:
dump()showsallvariablesintheframedump(obj)dumpsallthat'sknownabouttheobjectBroughttoyoubyDON'TPANIC,yourfriendlyWerkzeugpoweredtracebackinterpreter.
css代码:
使用UTF-8编码保存
>*{
>margin:0;
>}
>p{
>color:red;
>}
慕勒3428872
浏览 453回答 2
2回答

慕少森

刚开始我也遇到了CSS不生效的情况,试着排查了下,发现我把app放在了带有中文字符的文件夹里,移到非中文字符文件夹里就能生效了。

慕森王

看起來是常見的編碼問題,unicode跟string之間需要encode或decode的切換,可以看一下stacktrace找一下是哪裡有不是unicode的地方。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript