Невозможно передать параметры в вызов POST во время тестирования приложения Flask

Если вы используете примеры в readme, просто посмотрите на свойство length объекта rows (т. е. rows.length).

0
задан Sushant Kumar 17 January 2019 в 07:42
поделиться

3 ответа

def signup(self, username, password, confirm, client):
    return self.app.post(
        '/signup',
        data=json.dumps(dict(username=username, password=password, confirm=confirm, client=client)), content_type='application/json')
0
ответ дан Ranjeet Kumar 17 January 2019 в 07:42
поделиться

Mimetype должен быть установлен на mimetype='application/json' в качестве дополнительного параметра внутри пост-вызова.

def signup(self, username, password, confirm, client):
    return self.app.post(
        '/signup',
        data=json.dumps(dict(username=username, password=password, confirm=confirm, client=client)),
        follow_redirects=True, mimetype='application/json'
    )
0
ответ дан Sushant Kumar 17 January 2019 в 07:42
поделиться

Документы описывают атрибуты, доступные по запросу. В большинстве распространенных случаев request.data будет пустым, поскольку он используется в качестве запасного варианта:

request.data Contains the incoming request data as string in case it came with a mimetype Flask does not handle.

request.args: the key/value pairs in the URL query string
request.form: the key/value pairs in the body, from a HTML post form, or JavaScript request that isn't JSON encoded
request.files: the files in the body, which Flask keeps separate from form. HTML forms must use enctype=multipart/form-data or files will not be uploaded.
request.values: combined args and form, preferring args if keys overlap

Все это экземпляры MultiDict. Вы можете получить доступ к значениям, используя:

request.form['name']: use indexing if you know the key exists
request.form.get('name'): use get if the key might not exist
request.form.getlist('name'): use getlist if the key is sent multiple times and you want a list of values. get only returns the first value.
0
ответ дан Ashwin Golani 17 January 2019 в 07:42
поделиться
Другие вопросы по тегам:

Похожие вопросы: