Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 提供HTML+;CSS+;JS(角形)带烧瓶_Angularjs_Python 3.x_Flask_Static Pages - Fatal编程技术网

Angularjs 提供HTML+;CSS+;JS(角形)带烧瓶

Angularjs 提供HTML+;CSS+;JS(角形)带烧瓶,angularjs,python-3.x,flask,static-pages,Angularjs,Python 3.x,Flask,Static Pages,我想做的是,只需将HTML+css+js文件作为静态页面发送到一些路由上,如: @app.route('/', methods=[GET]) def index(): return <html+css+js> index.html <!DOCTYPE html> <html> <head> <title>Hello</title> <script type="text/j

我想做的是,只需将HTML+css+js文件作为静态页面发送到一些路由上,如:

@app.route('/', methods=[GET])
def index():
  return <html+css+js>
index.html

<!DOCTYPE html>

<html>
    <head>
        <title>Hello</title>
        <script type="text/javascript" src="{{ url_for('static', filename='main.js') }}"></script>
    </head>
    <body>
        <h1>Welcome!</h1>
    </body>
</html>
<!DOCTYPE html>

<html>
    <head>
        <title>Hello</title>
        <script type="text/javascript" src="{{ url_for('static', filename='main.js') }}"></script>
    </head>
    <body>
        <h1>Welcome!</h1>
    </body>
</html>

你好
欢迎
我得到的错误如下

127.0.0.1---[28/Oct/2015 14:07:02]“GET/abc/%7B%7B%20url_for('static',%20filename='main.js')%20%7D%7D HTTP/1.1”404-

HTML返回正常,但找不到
js
文件


将模板作为静态文件发送

app.send_static_file("index.html")

更好:)

如果不依赖模板,我将无法找到工作

以下几点对我有用

按如下方式重组我的目录

  • 重定向服务器
    • 静止的
      • main.js
    • 模板
      • index.html
    • main.py
main.py

from flask import Flask, redirect
from flask import render_template

app = Flask(__name__)

@app.route('/')
def index():
    return redirect("/abc/xyz")

@app.route('/abc/xyz')
def abc():
    return app.send_static_file("index.html")

app.run(debug=True)
from flask import Flask, redirect
from flask import render_template

app = Flask(__name__)

@app.route('/')
def index():
    return redirect("/abc/xyz")

@app.route('/abc/xyz')
def abc():
    return render_template("index.html")

app.run(debug=True)
index.html

<!DOCTYPE html>

<html>
    <head>
        <title>Hello</title>
        <script type="text/javascript" src="{{ url_for('static', filename='main.js') }}"></script>
    </head>
    <body>
        <h1>Welcome!</h1>
    </body>
</html>
<!DOCTYPE html>

<html>
    <head>
        <title>Hello</title>
        <script type="text/javascript" src="{{ url_for('static', filename='main.js') }}"></script>
    </head>
    <body>
        <h1>Welcome!</h1>
    </body>
</html>

你好
欢迎

上面已经提到,将其与js链接是不可能的working@IshanKhare:在服务器上替换这样的模板表达式正是flask、Django、Mason、Catalyst等的工作方式,而在这种范式机制下工作几乎没有成功的机会,更不用说交付可维护的代码了。你能详细说明你试图通过“将它与js链接[?]不起作用”来表达的具体症状吗?@IshanKhare做到了。你似乎也这么做了,因为从你自己的回答中,你似乎发现“127.0.0.1---[28/Oct/2015 14:07:02]”GET/abc/%7B%7B%20url_for('static',%20filename='main.js')%20%7D%7D HTTP/1.1“404-”只是服务器日志告诉你我用散文告诉你的内容的方式。由于我使用{},呈现模板不会起作用对于angular,jinja模板将在尝试将其解析为模板表达式时引发错误