Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
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
Am I forced to put favicon.ico in the static directory?

I know that it is recommended to put it in the static directory and then add a link tag for it,

but I am just using flask as an easy way to handle the http stuff since I want to do stuff manually for now to ingrain how everything actually works, so rather than having a static directory I add an @app.route for each route/file request.

This seems to work fine for the css, html, and JavaScript files and everything else, but for some reason, despite my browser sending a get request for the favicon using the correct route, flask does not handle that route.

In the flask app I have:

@app.route(“/Images/favicon.ico”)
def getFavicon():
return send_file(“Images/favicon.ico”, mimetype=“image/x-icon”)

In the html head element I have:

<link href=“Images/favicon.ico” rel=“icon” type=“image/x-icon” />


Also on the JavaScript console I see a 404 for the request, but the request does not even show up in the flask app output on the terminal.

Does flask act weird because it’s an icon or something?

/r/flask
https://redd.it/10dwkbo
Each event should have be able to have mutliple, People and Organisations.

from flask import Flask
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///project.db'
db = SQLAlchemy(app)


class Event(db.Model):
__tablename__ = 'Event'
#id = db.Column(db.Integer, primary_key=True)
person_id = db.Column(db.Integer, db.ForeignKey('Person.id'), primary_key=True)
organisation_id = db.Column(db.Integer, db.ForeignKey('Organisation.id'), primary_key=True)

people = db.relationship('Person', uselist=True, back_populates="events")
organisations = db.relationship('Organisation', uselist=True, back_populates="events")

title = db.Column(db.String(255))
body = db.Column(db.String(255))

class Person(db.Model):
__tablename__ = 'Person'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255))
password = db.Column(db.String(255))


/r/flask
https://redd.it/10dskrd
Read only object to share between sessions and requests

I have a look-up table which will be used in a read-only mode and should be created once when the flask server starts and maybe can be shared across the different requests to the server.

I am new to flask and web development and would you like to know the best way to achieve this in flask? The table is rather large (6 MBish) in size, so interested in minimizing memory overhead.

/r/flask
https://redd.it/10ddwm2
Mutable tuple views - einspect

Just finished adding all MutableSequence protocols for TupleViews. So pretty much all methods you can use on a list, you can now use on a tuple 👀

https://preview.redd.it/n14ywwpolkca1.png?width=1000&format=png&auto=webp&v=enabled&s=98373e593e60f58678265494f7ca9bc6739ea0b7

Feedback, issues, and PRs are welcome!

https://github.com/ionite34/einspect/

pip install einspect

A check also ensures resizes aren't outside of allocated memory. This means there is a limit to how much you can extend a tuple beyond its initial size.

from einspect import view

tup = (1, 2)
v = view(tup)

v: = 1, 2, 3, 4, 5
>> UnsafeError: setting slice required tuple to be resized beyond current memory allocation. Enter an unsafe context to allow this.

This is overrideable with an unsafe() context.

from einspect import view

tup = (1, 2)
v = view(tup)

with v.unsafe():
v: = 1, 2, 3, 4, 5

print(tup)
>> (1, 2, 3, 4, 5)
>>

/r/Python
https://redd.it/10e80md
Best/recommended road map for python beginner?? already met with the basics and now don't know what to start and where to start, just started python for job opportunities and now feeling energetic learning it but don't know what to do next



/r/Python
https://redd.it/10e39zq
CDF and PMF of binomial function not same with extreme values

Hello,
I wanted to calculate the chance that I inhale at least one molecule of Ceasars words (see here). I thought to calculate the chance of inhaling zero molecules and distract this value from 1 [1-(binom(0,n,p)\]

I used this code


from scipy.stats import binom
def calculate(n, p, r):
    print (f"{n=} {p=} {r=}")
    print  (f"PMF  The chance that you inhale {r} molecules {binom.pmf(r, n, p)}")
    print  (f"CDF The chance that you inhale {r} molecules {binom.cdf(r, n, p)}")
n = 25.0*10**21
p = 1.0*10**-21
r = 0
calculate(n, p, r)

My output is

PMF The chance that you inhale 0 molecules 1.0

CDF The chance that you inhale 0 molecules 1.388794386496407e-11

When I do normal values my output is the same

n=10 p=0.1 r=0

PMF The chance that you inhale 0 molecules 0.3486784401000001

CDF The chance that you inhale 0 molecules 0.34867844009999993

How is this possible?

/r/pystats
https://redd.it/10e8bvx
A flask app I’m working on. Feedback appreciated.
https://exoticonix.ml

/r/flask
https://redd.it/10edco9
Renaming folders is usually a bad idea right?

I tried renaming folders to add an "s" in VScode and it totally broke my project.

As a newbie I should avoid doing that, correct?

/r/djangolearning
https://redd.it/10dy6k8
E commerce with django.

Is django a good platform for making ecommerce. If yes do we have any templates which are good. Also what can I use as a payment gateway.

/r/djangolearning
https://redd.it/10dw5bs
Website not responding after AWS instanse was full and tried to update SSL certificate

Hi,

I have a website that is running in AWS EC2 Ubuntu instance. The site is built using Django and deployed with Nginx and Gunicorn. I just recently got my hands on this project and have not done any code for it.

The problem is that the SSL certificate of the site was expired and also the instance was full of logs so I just ran \`journalctl vacuum\` to delete some old logs. At this time the website was still accessible.

Then I generated new SSL cert using LetsEncrypt Certbot (First time doing this so didn't know you can just renew the existing one). After this the website stopped responding. Earlier it was working with ticking the 'accept security risk' from the browser but now nothing.

I have tried restarting the instance, Nginx and Gunicorn which should fix this but it hasn't worked. I also removed the newly generated SSL cert and tried to renew the old one but didn't work.

Any idea why the website is not responding and how can I fix it?

This stuff is new to me so any help is more than welcome. :)

Here are some files and outputs from the terminal that I think might be useful:

`systemctl

/r/djangolearning
https://redd.it/10dp2ru
Is MQ needed for sending many texts?

I have an API endpoint via Twiliio to send texts, and a lot will be sent each day, typically in batches all at once. The endpoints will be hit to do this. Is a full message queue needed to do this?

I was thinking just an async request like this https://github.com/spyoungtech/grequests along with Twilio's built in monitoring on success/not success could do without holding up the application?

/r/djangolearning
https://redd.it/10desde