Trying to build a dynamic Table using Flask/turbo/threading
Hey guys
Im currently trying to create a dynamicly updating table, housing some data and I'm slowly loosing it.
The problem is, no matter what I do, I can't seem to get it to consistently update.
The wierd thing is, sometimes it will randomly work,but it will start duplicating the "delete all" button with every update. And then after a quick reload of the side, without changing anything in the code, it won't update anymore.
I also sometimes get a "GET /turbo-stream HTTP/1.1" 500 -" error, and then without changing anything, just restarting frontend.py, it won't appear again.
The following code is what I have currently:
frontend.py:
import threading
import time
from flask import Flask, Response, render_template, url_for
from turbo_flask import Turbo
from Backend import Backend
app = Flask(__name__)
turbo = Turbo(app)
app.config['SERVER_NAME'] = '192.168.2.183:5000'
#This is what trap_data looks like (for a single entry):
#(141, '192.168.1.1', 'Authentication Failure', 'Invalid username or password', 3, 1,
/r/flask
https://redd.it/10dw2xv
Hey guys
Im currently trying to create a dynamicly updating table, housing some data and I'm slowly loosing it.
The problem is, no matter what I do, I can't seem to get it to consistently update.
The wierd thing is, sometimes it will randomly work,but it will start duplicating the "delete all" button with every update. And then after a quick reload of the side, without changing anything in the code, it won't update anymore.
I also sometimes get a "GET /turbo-stream HTTP/1.1" 500 -" error, and then without changing anything, just restarting frontend.py, it won't appear again.
The following code is what I have currently:
frontend.py:
import threading
import time
from flask import Flask, Response, render_template, url_for
from turbo_flask import Turbo
from Backend import Backend
app = Flask(__name__)
turbo = Turbo(app)
app.config['SERVER_NAME'] = '192.168.2.183:5000'
#This is what trap_data looks like (for a single entry):
#(141, '192.168.1.1', 'Authentication Failure', 'Invalid username or password', 3, 1,
/r/flask
https://redd.it/10dw2xv
reddit
Trying to build a dynamic Table using Flask/turbo/threading
Hey guys Im currently trying to create a dynamicly updating table, housing some data and I'm slowly loosing it. The problem is, no matter what...
Little confused how how data is passed from Python up to html
As many have probably seen from my incessant posts as of late, I have been writing a flashcard website. My starting point was a tutorial to write basic notes using a sqlalchemy and I've been fiddling around getting it to do what I want. One thing that confuses me is exactly how the html side is seeing all my database entries. So In python I have,
fetchedflash = Flashcard()
@views.route('/', methods = ["GET", "POST"]) #this is homepage route(url)
@loginrequired
def home():
...
return rendertemplate("home.html", user = currentuser...
Where current_user(something from flask_login I also don't fully understand yet) points to my user entry in the database. The User entry is tied to decks and flashcards also in the database entry.
The html has,
{% for deck in user.decks %}
...
And I'm really confused as to how the HTML is seeing all the deck elements in "user." IS the entire user database being
/r/flask
https://redd.it/1avpsge
As many have probably seen from my incessant posts as of late, I have been writing a flashcard website. My starting point was a tutorial to write basic notes using a sqlalchemy and I've been fiddling around getting it to do what I want. One thing that confuses me is exactly how the html side is seeing all my database entries. So In python I have,
fetchedflash = Flashcard()
@views.route('/', methods = ["GET", "POST"]) #this is homepage route(url)
@loginrequired
def home():
...
return rendertemplate("home.html", user = currentuser...
Where current_user(something from flask_login I also don't fully understand yet) points to my user entry in the database. The User entry is tied to decks and flashcards also in the database entry.
The html has,
{% for deck in user.decks %}
...
And I'm really confused as to how the HTML is seeing all the deck elements in "user." IS the entire user database being
/r/flask
https://redd.it/1avpsge
Reddit
From the flask community on Reddit
Explore this post and more from the flask community
How do I add a new entry to my many to many related table in Django?
I have two models Course and Educators. Course has 3 fields course\_name, course\_educators and course\_past\_educators which link Educators to Courses by many to many. I want to write a function so that whenever a new entry is added to course\_educators that entry will be copied over to course\_past\_educators.
#models.py
#code for Educators model
class Educators(models.Model):
educator_name=models.CharField(max_length=20,default=None)
educator_img = models.ImageField(upload_to='educators_img',default=None)
#code for Courses model
class Course(models.Model):
course_name = models.CharField(max_length=100)
course_educators=models.ManyToManyField(Educators, related_name='current_educators', default=None, blank=True)
course_past_educators=models.ManyToManyField(Educators, related_name='past_educators', default=None, blank=True)
#views.py
#This is the function I wrote so that entries into course_past_educators are automatically added when course_educators is added with another entry.
u/receiver(m2m_changed, sender=Course.course_educators.through)
def create_past_educator_on_add(sender, instance, action, reverse, model, pk_set, **kwargs):
if action == 'post_add' and reverse is False:
/r/djangolearning
https://redd.it/1cq2j42
I have two models Course and Educators. Course has 3 fields course\_name, course\_educators and course\_past\_educators which link Educators to Courses by many to many. I want to write a function so that whenever a new entry is added to course\_educators that entry will be copied over to course\_past\_educators.
#models.py
#code for Educators model
class Educators(models.Model):
educator_name=models.CharField(max_length=20,default=None)
educator_img = models.ImageField(upload_to='educators_img',default=None)
#code for Courses model
class Course(models.Model):
course_name = models.CharField(max_length=100)
course_educators=models.ManyToManyField(Educators, related_name='current_educators', default=None, blank=True)
course_past_educators=models.ManyToManyField(Educators, related_name='past_educators', default=None, blank=True)
#views.py
#This is the function I wrote so that entries into course_past_educators are automatically added when course_educators is added with another entry.
u/receiver(m2m_changed, sender=Course.course_educators.through)
def create_past_educator_on_add(sender, instance, action, reverse, model, pk_set, **kwargs):
if action == 'post_add' and reverse is False:
/r/djangolearning
https://redd.it/1cq2j42
Reddit
From the djangolearning community on Reddit
Explore this post and more from the djangolearning community
CSRF Token Error
Hey I get this CSRF Token Error on my webserver.
i dont get where this is coming from because they are the same token before and after.
I checked my steinngs and my conf and cant find the error.
https://preview.redd.it/ar4qu70h4ste1.png?width=1222&format=png&auto=webp&s=28e79c8dc2338487301ac0a1fd642096dbe7097d
https://preview.redd.it/nkco18wj4ste1.png?width=1210&format=png&auto=webp&s=0d2ba8ec728bac99aad92f52527fd353ba6cb815
#This is my settigs for nginx
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
# Security headers
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
X_FRAME_OPTIONS = "DENY"
# HSTS settings
SECURE_HSTS_SECONDS = 31536000 # 1 year
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
/r/djangolearning
https://redd.it/1jv1s9a
Hey I get this CSRF Token Error on my webserver.
i dont get where this is coming from because they are the same token before and after.
I checked my steinngs and my conf and cant find the error.
https://preview.redd.it/ar4qu70h4ste1.png?width=1222&format=png&auto=webp&s=28e79c8dc2338487301ac0a1fd642096dbe7097d
https://preview.redd.it/nkco18wj4ste1.png?width=1210&format=png&auto=webp&s=0d2ba8ec728bac99aad92f52527fd353ba6cb815
#This is my settigs for nginx
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
# Security headers
SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True
X_FRAME_OPTIONS = "DENY"
# HSTS settings
SECURE_HSTS_SECONDS = 31536000 # 1 year
SECURE_HSTS_INCLUDE_SUBDOMAINS = True
SECURE_HSTS_PRELOAD = True
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
/r/djangolearning
https://redd.it/1jv1s9a
db.init_app(app) Errror
Hi I am a compleat Noob (in flask), i have an Error in my Program that says: TypeError: SQLAlchemy.init\_app() missing 1 required positional argument: 'app' and i dont know what is wrong ):
This is the code pls Help me:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from os import path
db = SQLAlchemy
DB_NAME = "database.db"
def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = 'hjshjhdjah kjshkjdhjs'
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{DB_NAME}'
db.init_app(app) #this thing makes the problem
from .views import views #thies are just website things
from .auth import auth
app.register_blueprint(views, url_prefix='/')
app.register_blueprint(auth, url_prefix='/')
from .models import User, Note #that are moduls for the data base
with app.app_context():
/r/flask
https://redd.it/1kmg69c
Hi I am a compleat Noob (in flask), i have an Error in my Program that says: TypeError: SQLAlchemy.init\_app() missing 1 required positional argument: 'app' and i dont know what is wrong ):
This is the code pls Help me:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from os import path
db = SQLAlchemy
DB_NAME = "database.db"
def create_app():
app = Flask(__name__)
app.config['SECRET_KEY'] = 'hjshjhdjah kjshkjdhjs'
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{DB_NAME}'
db.init_app(app) #this thing makes the problem
from .views import views #thies are just website things
from .auth import auth
app.register_blueprint(views, url_prefix='/')
app.register_blueprint(auth, url_prefix='/')
from .models import User, Note #that are moduls for the data base
with app.app_context():
/r/flask
https://redd.it/1kmg69c
Reddit
From the flask community on Reddit
Explore this post and more from the flask community
Having trouble writing to .txt and CSV files while Flask is running.
So I am trying to write simple submission form text from a website to a text file. The form submits fine and I can even print out my data, but it won't write to a text or csv file for some reason. No errors, the file is just empty. I run the same snippit of code in another file that isn't running flask and the code works fine. It writes to the text file. I can even print out the form text and see it in the debug console; but it just won't write to a file. I feel like I'm in the twilight zone.
#this function should work, but it does'nt
def writetotext(data):
with open('DataBase.txt',mode='a') as database:
email=data'email'
subject=data'subject'
message=data'message'
print(f'\n{email},{subject},{message}')
file=database.write(f'\n{email},{subject},{message}')
/r/flask
https://redd.it/1on2o1l
So I am trying to write simple submission form text from a website to a text file. The form submits fine and I can even print out my data, but it won't write to a text or csv file for some reason. No errors, the file is just empty. I run the same snippit of code in another file that isn't running flask and the code works fine. It writes to the text file. I can even print out the form text and see it in the debug console; but it just won't write to a file. I feel like I'm in the twilight zone.
#this function should work, but it does'nt
def writetotext(data):
with open('DataBase.txt',mode='a') as database:
email=data'email'
subject=data'subject'
message=data'message'
print(f'\n{email},{subject},{message}')
file=database.write(f'\n{email},{subject},{message}')
/r/flask
https://redd.it/1on2o1l
Reddit
From the flask community on Reddit
Explore this post and more from the flask community