标签: flask-restless

在 SQLAlchemy 中执行连接时出错“请明确指定此连接的‘onclause’。”

我使用flask-sqlalchemy有以下sqlalchemy模型。我的日程安排模型中有 3 个人才偏好项目。总是需要 3 个并且不会更少。

class TalentPref(db.Model):
    __tablename__ = 'talentpref'
    id = db.Column(db.Integer, primary_key=True)
    firstName = db.Column(db.String(80), unique=True)
    lastName = db.Column(db.String(80), unique=True)

    def __init__(self, firstName, lastName):
        self.firstName = firstName
        self.lastName = lastName

    def __repr__(self):
        return '<talentpref %r %r>' % (self.firstName, self.lastName)

class Schedule(db.Model):
    __tablename__ = 'schedule'

    id = db.Column(db.Integer, primary_key=True)

    talentpref1_id = db.Column(db.Integer, db.ForeignKey('talentpref.id'))
    talentpref2_id = db.Column(db.Integer, db.ForeignKey('talentpref.id'))
    talentpref3_id = db.Column(db.Integer, db.ForeignKey('talentpref.id'))

    talentpref1 = db.relationship("TalentPref", uselist=False, foreign_keys=talentpref1_id)
    talentpref2 = db.relationship("TalentPref", uselist=False, foreign_keys=talentpref2_id)
    talentpref3 = db.relationship("TalentPref", uselist=False, foreign_keys=talentpref3_id)
Run Code Online (Sandbox Code Playgroud)

我正在使用 flask-restless 将调度模型作为 …

python sqlalchemy flask-sqlalchemy flask-restless

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

在flask-restless预处理器中访问请求标头

我正在使用Flask-Restless构建一个API,它需要一个API密钥,它将位于AuthorizationHTTP标头中.

在Flask-Restless示例中,这里有一个预处理器:

def check_auth(instance_id=None, **kw):
    # Here, get the current user from the session.
    current_user = ...
    # Next, check if the user is authorized to modify the specified
    # instance of the model.
    if not is_authorized_to_modify(current_user, instance_id):
        raise ProcessingException(message='Not Authorized',
                                  status_code=401)
manager.create_api(Person, preprocessors=dict(GET_SINGLE=[check_auth]))
Run Code Online (Sandbox Code Playgroud)

如何检索函数中的Authorization标题check_auth

我试过访问Flask response对象,但它是None在这个函数的范围内.该kw参数也是一个空字典.

python flask flask-restless

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

如何在<td>标签中给出烧瓶删除方法的超链接

如何为烧瓶删除方法提供超链接.这是代码HTML代码.我用HTML编写了超链接.那么,如何在烧瓶路线中传递url.我正在使用Flask框架,我试图从数据库中删除一个条目.下面的代码给出了这个错误:"请求的URL不允许使用该方法."

{% extends "base.html" %}
{% block head %}
{{super()}}
{% endblock %}
{% block navbar %}
{{super()}}
{% endblock %}
{% block content %}
<div class="row">
<ol class="breadcrumb">
<li><a href="#">
<em class="fa fa-home"></em> </a></li>
<li class="active">Users>View/Edit</li>
</ol>
</div><!--/.row-->
<div class="row">
<div class="col-md-12">
<table class="table table-striped table-hover">

<thead>
<tr>
    <th>
        Name
    </th>
    <th>
       Email
   </th>
   <th>
       Address
   </th>
   <th>
       Aadharimage
   </th>

   <th>
       Password
   </th>
   <th>
      Locations
   </th>
   <th>
      Dateofsub
   </th>
   <th>
     Lastlogin
   </th>
   <th>
     Control
</th>
<th>
Delete
</th>
</tr> …
Run Code Online (Sandbox Code Playgroud)

html python flask flask-sqlalchemy flask-restless

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

为Flask-Restless API序列化Python Arrow对象

我目前正在使用Flask-Restless开发应用程序。当我用相应的箭头字段替换我的SQLAlchemy模型的典型DateTime字段时,所有操作都很顺利。这是由于SQLAlchemy-Utils及其ArrowType字段的帮助。

但是,在使用API​​返回这些对象的JSON表示后,我收到以下错误:

TypeError:箭头[2015-01-05T01:17:48.074707]不可序列化JSON

修改模型序列化的理想位置在哪里?是否修改Flask-Restless代码以支持Arrow对象或编写Flask-Restless可以识别并用于检索JSON兼容对象的模型方法?

同时,我还可以编写一个丑陋的后处理器函数,但该解决方案似乎是一个可怕的hack。

下面是带有ArrowType字段的示例模型:

class Novel(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.Unicode, unique=True, nullable=False)
    created_at = db.Column(ArrowType, nullable=False)

    def __init__(self, title):
        self.title = title
        self.created_at = arrow.utcnow()
Run Code Online (Sandbox Code Playgroud)

python serialization json flask-restless

0
推荐指数
1
解决办法
1625
查看次数