javascript - AngularJS 未在 Flask 应用程序中运行

标签 javascript python node.js angularjs flask

我正在按照这个简单的教程创建一个 pinterest 克隆。 http://blog.jetbrains.com/pycharm/2013/12/video-pycharm-web-magic-building-a-pinterest-clone/

我在使用 Angular 时遇到问题。

html代码:

<!DOCTYPE html>
<html>
<head>
    <title>Pin Clone</title>
</head>
<body ng-app1="app1" ng-controller="AppCtrl as app1">

{{ app1.message }}

<script src="bower_components/angular/angular.js"></script>
<script src="js/app1.js"></script>
</body>
</html>

app1.js代码:

var app1 = angular.module("app1", []);

app1.controller("AppCtrl", function () {
    var app1 = this;
    app1.message = "not working"
})

当我重新加载页面时,我只是看到了文本: {{ app1.message }} 这是在浏览器中。

控制台在重新加载时声明:

127.0.0.1 - - [07/Jun/2014 12:59:50] "GET / HTTP/1.1" 304 -
127.0.0.1 - - [07/Jun/2014 12:59:50] "GET /bower_components/angular/angular.js HTTP/1.1"     304 -
127.0.0.1 - - [07/Jun/2014 12:59:50] "GET /js/app1.js HTTP/1.1" 304 -

这是在 Ubuntu 14.04 上。我正在使用 Bower 将 Angular 安装到项目中。

AngularJS 版本 1.2.17

凉亭 1.3.4

Node 版本 v0.10.28

npm 版本 1.4.9

项目文件夹:

folders

编辑1,Home_Site.py中的Flask代码:

from flask import Flask
from flask.ext.restless.manager import APIManager
from flask.ext.sqlalchemy import SQLAlchemy
from sqlalchemy import Column, Integer, Text

# instantiating Flask
app = Flask(__name__, static_url_path='')
# setting the SQLALCHEMY_DATABASE_URI to the pin database
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///pin.db'

# setting an instance of SQLAlchemy
db = SQLAlchemy(app)

# creates a database model with an id, title, image
class Pin(db.Model):
    id = Column(Integer, primary_key=True)
    title = Column(Text, unique=False)
    image = Column(Text, unique=False)

db.create_all()

# automatically creates an api for the pins in the db
# api stands for application programming interface
api_manager = APIManager(app, flask_sqlalchemy_db=db)
api_manager.create_api(Pin, methods=['GET', 'POST', 'DELETE', 'PUT'])

# type route and hit tab to create this
# this allows you to route to the main html file in the static folder
@app.route('/')
def index1():
    return app.send_static_file('index1.html')

# reloads the server on its own
app.debug = True

if __name__ == '__main__':
    app.run()

最佳答案

您的 ngApp 声明中有错字:

<body ng-app1="app1" ng-controller="AppCtrl as app1">

应该是:

<body ng-app="app1" ng-controller="AppCtrl as app1">

(注意 ng-app 声明中缺少 1。)

关于javascript - AngularJS 未在 Flask 应用程序中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24099818/

相关文章:

javascript - 如何根据第一个下拉列表值使第二个下拉列表自动选择值

javascript - 如何使用 react Hook 将 HTML 复制到剪贴板?

javascript - Fabric.js 函数将物体从 A 点移动到 B 点

python - 使用 arctan/arctan2 绘制 a 从 0 到 2π

python - 如何删除给出这个的vscode自动完成?

javascript - 无法使用 mysql 包从我的 node.js 应用程序连接到数据库

javascript - 无法传递 mongoose 数据来查看 Jade

javascript - 使子 ul 在页面加载时向下滑动

python - Django 模板 : Comparing Dictionary Length in IF Statement

javascript - 如何确保socket.io-client消息已被socket.io服务器收到?