小编lor*_*. j的帖子

如何在蓝图中访问app.config?

我试图authorisation.py在包api中的蓝图内访问访问应用程序配置.我正在初始化__init__.py其中使用的蓝图authorisation.py.

__init__.py

from flask import Blueprint
api_blueprint = Blueprint("xxx.api", __name__, None)
from api import authorisation
Run Code Online (Sandbox Code Playgroud)

authorisation.py

from flask import request, jsonify, current_app

from ..oauth_adapter import OauthAdapter
from api import api_blueprint as api

client_id = current_app.config.get('CLIENT_ID')
client_secret = current_app.config.get('CLIENT_SECRET')
scope = current_app.config.get('SCOPE')
callback = current_app.config.get('CALLBACK')

auth = OauthAdapter(client_id, client_secret, scope, callback)


@api.route('/authorisation_url')
def authorisation_url():
    url = auth.get_authorisation_url()
    return str(url)
Run Code Online (Sandbox Code Playgroud)

我得到RuntimeError:在应用程序上下文之外工作

我明白为什么会这样,但是访问这些配置设置的正确方法是什么?

----更新----暂时,我已经这样做了.

@api.route('/authorisation_url')
def authorisation_url():
    client_id, client_secret, scope, callback = config_helper.get_config()
    auth = OauthAdapter(client_id, client_secret, …
Run Code Online (Sandbox Code Playgroud)

flask

94
推荐指数
6
解决办法
4万
查看次数

Peewee KeyError:'我'

我从Python的peewee模块得到一个奇怪的错误,我无法解决,任何想法?我基本上希望拥有包含多个公司的"批次".我正在为每个批处理创建一个批处理实例,并将其中的所有公司分配给该批处理的行ID.

追溯

Traceback (most recent call last):
  File "app.py", line 16, in <module>
    import models
  File "/Users/wyssuser/Desktop/dscraper/models.py", line 10, in <module>
    class Batch(Model):
  File "/Library/Python/2.7/site-packages/peewee.py", line 3647, in __new__
    cls._meta.prepared()
  File "/Library/Python/2.7/site-packages/peewee.py", line 3497, in prepared
    field = self.fields[item.lstrip('-')]
KeyError: 'i'
Run Code Online (Sandbox Code Playgroud)

models.py

from datetime import datetime

from flask.ext.bcrypt import generate_password_hash
from flask.ext.login import UserMixin

from peewee import *

DATABASE = SqliteDatabase('engineering.db')

class Batch(Model):
  initial_contact_date = DateTimeField(formats="%m-%d-%Y")

  class Meta:
    database = DATABASE
    order_by = ('initial_contact_date')

  @classmethod
  def create_batch(cls, initial_contact_date):
    try:
      with …
Run Code Online (Sandbox Code Playgroud)

python flask peewee

4
推荐指数
1
解决办法
938
查看次数

为什么总是将输出显示为1?

def power(x,n):
    if n == 0:
        return 1
    elif n % 2 == 0:
        return power(x * x, n % 2)
    else:
        return x * power(x, n - 1)
print power(2,3)
Run Code Online (Sandbox Code Playgroud)

我给它的输入是显示1还是2.任何人都可以在我出错的地方帮助我.我是编程的新手.谢谢

python python-2.7

2
推荐指数
1
解决办法
87
查看次数

标签 统计

flask ×2

python ×2

peewee ×1

python-2.7 ×1