Posts

Showing posts with the label flask

Specify the lines of textfield to display

Specify the lines of textfield to display I want to make a preview of my article. How to select first several lines of TextField ? I am using the flask and wtforms. TextField class Blog(Model): content = TextField() template: {{blog.content}} But how to specify the first several lines to display? For example, only display 4 lines. blog.content(rows = 4) blog.content(rows = 4) 1 Answer 1 If blog.content consists of lines separated by newline characters, you can just split the content by newline and return the first four elements, joined: blog.content >>> content = 'OnenTwonThreenFournFivenSix' >>> parts = content.split('n') >>> preview = 'n'.join(parts[:4]) >>> preview # use this in the template {{ preview }} 'OnenTwonThreenFour' If blog.content does not consist of lines separated by newline characters, you could use jinj...

Heroku crashes with a jwt error [on hold]

Heroku crashes with a jwt error [on hold] i have created a flask app that uses JWT for authentification. The app crashes on Heroku with the following log details. from jwt import ExpiredSignatureError, InvalidTokenError ImportError: cannot import name 'ExpiredSignatureError' I dont have any such import in my code from jwt import ExpiredSignatureError, InvalidTokenError ImportError: cannot import name 'ExpiredSignatureError' App logs This question appears to be off-topic. The users who voted to close gave this specific reason:

Audio Livestreaming with Python & Flask

Audio Livestreaming with Python & Flask I'm currently strugling with my implementation of a simple live streaming web application using Python and Flask. It seems that I'm not able to stream my live recorded audio from the servers microphone input to the webpage. server.py from flask import Flask, render_template, Response import cv2 import framework import pyaudio import audio_processing as audioRec FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 44100 CHUNK = 1024 audio = pyaudio.PyAudio() app = Flask(__name__) @app.route('/') def index(): """Video streaming home page.""" return render_template('index.html') # Stream routing @app.route('/video_feed') def video_feed(): """Video streaming route. Put this in the src attribute of an img tag.""" return Response(generateVideo(), mimetype='multipart/x-mixed-replace; boundary=frame') @app.route("/audio...