Can I add column to the result of a query?
I query a table like this:
I get something in return that looks like this:
Can I add to this so that it will look like this:
I tried this:
and that doesn't work.
Am I supposed to
/r/flask
https://redd.it/12ley46
I query a table like this:
check = Example.query.filter_by(example_attribute=1).all()I get something in return that looks like this:
[Example('1','something', something again')]Can I add to this so that it will look like this:
[Example('1', 'something', 'something again', 'another something')]I tried this:
for x in check:
x.add_columns({'added column': 'another something'})
and that doesn't work.
Am I supposed to
JSON.dumps this and then add it?/r/flask
https://redd.it/12ley46
Reddit
r/flask on Reddit: Can I add column to the result of a query?
Posted by u/miamiredo - 2 votes and 5 comments
Pdfkit vs weasyprint ?
I have a pretty heavy website and want to generate pdf tickets , can be up to 20 per user per order, I already have pdfkit installed and working nicely with a small users number. But as my website grows I ask myself what is the better option between those two? Or is there a better third option …
My main concern is scalability and performance, my setup is a docker compose with django and celery for async pdf generation, hosted on aws elastic beanstalk with their auto scaling.
Can someone share his experience with pdf generation in django ?
Thanks guys for reading
/r/django
https://redd.it/12m7t68
I have a pretty heavy website and want to generate pdf tickets , can be up to 20 per user per order, I already have pdfkit installed and working nicely with a small users number. But as my website grows I ask myself what is the better option between those two? Or is there a better third option …
My main concern is scalability and performance, my setup is a docker compose with django and celery for async pdf generation, hosted on aws elastic beanstalk with their auto scaling.
Can someone share his experience with pdf generation in django ?
Thanks guys for reading
/r/django
https://redd.it/12m7t68
Reddit
r/django on Reddit: Pdfkit vs weasyprint ?
Posted by u/Then_Level7997 - 8 votes and 12 comments
Django REST Framework's TokenAuthentication VS JWTs
Hello guys, can someone explain why they would prefer one over the other? In terms of security, use case etc.
/r/django
https://redd.it/12mhff1
Hello guys, can someone explain why they would prefer one over the other? In terms of security, use case etc.
/r/django
https://redd.it/12mhff1
Reddit
r/django on Reddit: Django REST Framework's TokenAuthentication VS JWTs
Posted by u/Charlesu49 - 3 votes and 2 comments
Saturday Daily Thread: Resource Request and Sharing! Daily Thread
Found a neat resource related to Python over the past week? Looking for a resource to explain a certain topic?
Use this thread to chat about and share Python resources!
/r/Python
https://redd.it/12mirgo
Found a neat resource related to Python over the past week? Looking for a resource to explain a certain topic?
Use this thread to chat about and share Python resources!
/r/Python
https://redd.it/12mirgo
Reddit
r/Python on Reddit: Saturday Daily Thread: Resource Request and Sharing! Daily Thread
Posted by u/Im__Joseph - 1 vote and no comments
How to generate URL from @app.route url in FLASK?
I have a Flask code with decorator u/app.route(/bestApp) to fetch my data from Fetch API javascript.
this is my app.py :
​
​
@
​
​
and this is my script.js
​
​
​
​
​
whenever i download my file, it works but the problem is the link that shown in browser is like “http://127.0.0.1:5000/bestApp”
how to convert http://127.0.0.1:5000/bestApp to normal URL? such http://127.0.0.1:5000/42342jnkjsahdkajsda87391237921dask.
I don’t wanna use Blob Object Url or Data URI.
/r/flask
https://redd.it/12kkjfd
I have a Flask code with decorator u/app.route(/bestApp) to fetch my data from Fetch API javascript.
this is my app.py :
​
​
@
app.route('/bestApp', methods=['GET', 'POST'])def bestapp():app_data = AppDataFromUrl(app_url)json.dumps(app_data)permitted_directory='static/assets/upload/'return send_from_directory(directory=permitted_directory, path=filename,as_attachment=True)​
​
and this is my script.js
​
​
async function getExtract() {try {const response = await fetch("/bestApp", {method: "post",body: new FormData(document.querySelector(".testform")),});​
console.log(response);}​
​
whenever i download my file, it works but the problem is the link that shown in browser is like “http://127.0.0.1:5000/bestApp”
how to convert http://127.0.0.1:5000/bestApp to normal URL? such http://127.0.0.1:5000/42342jnkjsahdkajsda87391237921dask.
I don’t wanna use Blob Object Url or Data URI.
/r/flask
https://redd.it/12kkjfd
Reddit
r/flask on Reddit: How to generate URL from @app.route url in FLASK?
Posted by u/Ok-Entertainment7595 - 2 votes and 5 comments
This week I made my first ever python script! It scrapes and translates a single Japanese website for hotel bookings asynchronously. Please come take a look :)
There is a hotel in Japan that will give you the insanely low price of $40 per night if you book a 30 day chunk all at once. Their site only lets you search a single location one day at a time though, so I decided to make this and learn everything from scratch along the way. The most ironic part is, I didn't find a single booking! I think they discontinued the offer... I was going to make a frontend with English translations for regular use too...
I'm openly accepting tips and advice on how to design these things better. It's probably pretty simple for you, but it took me awhile to figure out! Eventually I'd like to swap careers into tech :) If you have any ideas for what to make next be sure to leave your suggestion!
The code on github: https://github.com/Gornel/apa\_scraper/blob/main/list\_gatherer.py
A youtube of the first time I ran it: https://www.youtube.com/watch?v=cGUOLdaKBuE
/r/Python
https://redd.it/12m6obx
There is a hotel in Japan that will give you the insanely low price of $40 per night if you book a 30 day chunk all at once. Their site only lets you search a single location one day at a time though, so I decided to make this and learn everything from scratch along the way. The most ironic part is, I didn't find a single booking! I think they discontinued the offer... I was going to make a frontend with English translations for regular use too...
I'm openly accepting tips and advice on how to design these things better. It's probably pretty simple for you, but it took me awhile to figure out! Eventually I'd like to swap careers into tech :) If you have any ideas for what to make next be sure to leave your suggestion!
The code on github: https://github.com/Gornel/apa\_scraper/blob/main/list\_gatherer.py
A youtube of the first time I ran it: https://www.youtube.com/watch?v=cGUOLdaKBuE
/r/Python
https://redd.it/12m6obx
GitHub
apa_scraper/list_gatherer.py at main · Gornel/apa_scraper
Look for bookings on apahotel.com. Contribute to Gornel/apa_scraper development by creating an account on GitHub.
Here's my project to explore stress control through controlled breathing using Python, BLE, and the Polar H10 Heart Rate monitor
Hey r/Python,
I've been exploring the data available from the widely available Polar H10 heart rate monitor. The Bleak package provides a simple way to connect to the device, and stream heart rate, acceleration, and ECG data.
In this project I looked into the relationship between breathing rate and heart rate variability, a common indicator of physiological stress response.
Github repo: https://github.com/kbre93/dont-hold-your-breath
/r/Python
https://redd.it/12mi0ij
Hey r/Python,
I've been exploring the data available from the widely available Polar H10 heart rate monitor. The Bleak package provides a simple way to connect to the device, and stream heart rate, acceleration, and ECG data.
In this project I looked into the relationship between breathing rate and heart rate variability, a common indicator of physiological stress response.
Github repo: https://github.com/kbre93/dont-hold-your-breath
/r/Python
https://redd.it/12mi0ij
GitHub
GitHub - kieranabrennan/dont-hold-your-breath: Breathing analysis with Polar H10 Heart Rate Monitor
Breathing analysis with Polar H10 Heart Rate Monitor - kieranabrennan/dont-hold-your-breath
What is the best way to store marketplace commissions and payouts in a database after each purchase?
The basic idea is that the marketplace takes payments on behalf of the businesses and every 2 weeks the platform sends the money to the business while keeping 5% as commission.
Each time a user purchases a product we create a new Purchase object:
class Purchase(models.Model):
created = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(User)
product = models.ForeignKey(Product)
quantity = models.IntegerField(null=True, blank=True)
price = models.DecimalField(max_digits=10, decimal_places=2)
total_price = models.DecimalField(max_digits=10, decimal_places=2)
​
Apart from this, we need to store commissions and payouts information in our database. I was thinking of creating 3 models:
* PlatformComission (gets created each time a purchase happens, and stores the amount that we earned on that purchase)
* BusinessEarning (gets created each time a purchase happens, and stores the amount we need to pay the business)
* Payout (gets created every 2 weeks when the payout is sent, gets linked to all the Business Earnings during those 2 weeks with a many to many
/r/django
https://redd.it/12msfa6
The basic idea is that the marketplace takes payments on behalf of the businesses and every 2 weeks the platform sends the money to the business while keeping 5% as commission.
Each time a user purchases a product we create a new Purchase object:
class Purchase(models.Model):
created = models.DateTimeField(auto_now_add=True)
user = models.ForeignKey(User)
product = models.ForeignKey(Product)
quantity = models.IntegerField(null=True, blank=True)
price = models.DecimalField(max_digits=10, decimal_places=2)
total_price = models.DecimalField(max_digits=10, decimal_places=2)
​
Apart from this, we need to store commissions and payouts information in our database. I was thinking of creating 3 models:
* PlatformComission (gets created each time a purchase happens, and stores the amount that we earned on that purchase)
* BusinessEarning (gets created each time a purchase happens, and stores the amount we need to pay the business)
* Payout (gets created every 2 weeks when the payout is sent, gets linked to all the Business Earnings during those 2 weeks with a many to many
/r/django
https://redd.it/12msfa6
Reddit
r/django on Reddit: What is the best way to store marketplace commissions and payouts in a database after each purchase?
Posted by u/adrenaline681 - No votes and no comments
Choose Your Weapon: Survival Strategies for Depressed AI Academics
https://arxiv.org/abs/2304.06035
/r/MachineLearning
https://redd.it/12lxavs
https://arxiv.org/abs/2304.06035
/r/MachineLearning
https://redd.it/12lxavs
Reddit
r/MachineLearning on Reddit: Choose Your Weapon: Survival Strategies for Depressed AI Academics
Posted by u/togelius - No votes and 16 comments
[R] Bert and XLNet: 85% Neurons Redundant, 92% Removable for Downstream Tasks
https://aclanthology.org/2020.emnlp-main.398.pdf
/r/MachineLearning
https://redd.it/12ms3wo
https://aclanthology.org/2020.emnlp-main.398.pdf
/r/MachineLearning
https://redd.it/12ms3wo
New search package in python
Searchlix
My first python package on PyPI
I want to try how I can develop a python package and upload it, and the result was: Searchlix
It is a simple and powerful package which helps with searching for patterns, emails, phone numbers and words in texts and websites! (Web scraping)
Some of the features:
-Patterns search in text (KMP algorithm)
-Word search in text
-Search for page name in website
-Find emails in text / Email validation
-Find emails in a website page
-Find a phone number in text / Phone number validation
-Find a phone number in a website page
And I will provide further features and examples in the future
I would be thankful if any one who tried it could show us how he used it (case study) and if there are any further suggestions
https://pypi.org/project/searchlix/
/r/Python
https://redd.it/12mw0dc
Searchlix
My first python package on PyPI
I want to try how I can develop a python package and upload it, and the result was: Searchlix
It is a simple and powerful package which helps with searching for patterns, emails, phone numbers and words in texts and websites! (Web scraping)
Some of the features:
-Patterns search in text (KMP algorithm)
-Word search in text
-Search for page name in website
-Find emails in text / Email validation
-Find emails in a website page
-Find a phone number in text / Phone number validation
-Find a phone number in a website page
And I will provide further features and examples in the future
I would be thankful if any one who tried it could show us how he used it (case study) and if there are any further suggestions
https://pypi.org/project/searchlix/
/r/Python
https://redd.it/12mw0dc
PyPI
searchlix
A package for extract data from websites and text
Mastering SOLID Principles in Python: A Guide to Scalable Code
The Single Responsibility Principle (SRP) is a fundamental SOLID principle that states that a class should have only one reason to change.
/r/Python
https://redd.it/12mxuoi
The Single Responsibility Principle (SRP) is a fundamental SOLID principle that states that a class should have only one reason to change.
/r/Python
https://redd.it/12mxuoi
Reddit
r/Python on Reddit: Mastering SOLID Principles in Python: A Guide to Scalable Code
Posted by u/Olatunde32 - No votes and 2 comments
Basic question on what this syntax comes from: is this python code I am not familiar with; is it django -- Just not sure what to even call it so i can look up info on it.
/r/django
https://redd.it/12n1r76
/r/django
https://redd.it/12n1r76
Is having a single app standard in Django realm ?
hi there,
i started this new job as a Django backend developer. we have around 20 models. what i want to do is split them into couple apps along with their respective views etc. but my team mate argued that what i do is not right and all Django projects use a single app to manage everything.
is this correct ? what is the right way of doing this. a single app with 20 models in a models.py file seems hard to read/reach for me.
should i create separate apps or should i create multiple folders in a single app.
how do you structure your projects ?
/r/django
https://redd.it/12mwx7e
hi there,
i started this new job as a Django backend developer. we have around 20 models. what i want to do is split them into couple apps along with their respective views etc. but my team mate argued that what i do is not right and all Django projects use a single app to manage everything.
is this correct ? what is the right way of doing this. a single app with 20 models in a models.py file seems hard to read/reach for me.
should i create separate apps or should i create multiple folders in a single app.
how do you structure your projects ?
/r/django
https://redd.it/12mwx7e
Reddit
r/django on Reddit: Is having a single app standard in Django realm ?
Posted by u/everlastingflower - 4 votes and 7 comments
I discovered that the fastest way to create a Pandas DataFrame from a CSV file is to actually use Polars
https://medium.com/@finndersen/the-fastest-way-to-read-a-csv-file-in-pandas-2-0-532c1f978201
/r/Python
https://redd.it/12n0wfk
https://medium.com/@finndersen/the-fastest-way-to-read-a-csv-file-in-pandas-2-0-532c1f978201
/r/Python
https://redd.it/12n0wfk
Medium
The fastest way to read a CSV file in Pandas 2.0
It turns out that the fastest way to create a Pandas DataFrame from a CSV file is to use an entirely different library.
Django + Nextjs overkill?
I have built Django websites in the past as well as DRF + React. I know that the cool kids nowadays use Nextjs. It does indeed have a lot of good stuff but I feel kindda lost whether is a nice idea to combine the two frameworks and just use Nextjs as the frontend. I have read some posts mentioning that you will find a lot of problems down the road (CORS related, etc).
The reason to stick with DRF as backend is that I'm way more better developer and more used to python while I just know a couple of things in the Javascript world.
Any experience stories, guidance would be much appreaciated.
/r/django
https://redd.it/12neaj8
I have built Django websites in the past as well as DRF + React. I know that the cool kids nowadays use Nextjs. It does indeed have a lot of good stuff but I feel kindda lost whether is a nice idea to combine the two frameworks and just use Nextjs as the frontend. I have read some posts mentioning that you will find a lot of problems down the road (CORS related, etc).
The reason to stick with DRF as backend is that I'm way more better developer and more used to python while I just know a couple of things in the Javascript world.
Any experience stories, guidance would be much appreaciated.
/r/django
https://redd.it/12neaj8
Reddit
r/django on Reddit: Django + Nextjs overkill?
Posted by u/Scellillo - No votes and no comments
Sunday Daily Thread: What's everyone working on this week?
Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.
/r/Python
https://redd.it/12nnqs3
Tell /r/python what you're working on this week! You can be bragging, grousing, sharing your passion, or explaining your pain. Talk about your current project or your pet project; whatever you want to share.
/r/Python
https://redd.it/12nnqs3
Reddit
r/Python on Reddit: Sunday Daily Thread: What's everyone working on this week?
Posted by u/Im__Joseph - 1 vote and 2 comments
Pip 23.1 Released - Massive improvement to backtracking
Pip 23.1 was just released a few hours ago. You can check the release announcements here and the change log here.
I would like to highlight the significant improvement in backtracking that is part of the requirement resolver process in Pip. This process involves Pip finding a set of packages that meet your requirements and whose requirements themselves don't conflict.
For example, let's say you require packages A and B. First, the latest versions of A and B are downloaded and Pip checks their requirements, let's say Pip finds that A depends on C==2 and B depends on C==1. These two latest versions of A and B are not compatible, so Pip will try to find an older version of A and/or B where they have compatible dependencies. C in this case is called a transitive dependency because it's a dependency of a dependency.
Prior to Pip 20.3, the default process for Pip would allow conflicting requirements to install if they were transitive dependencies where the last one specified would be the one installed. This was not satisfactory for a lot of projects that had larger set of requirements because it meant package versions that did not work together could be installed
/r/Python
https://redd.it/12n5lai
Pip 23.1 was just released a few hours ago. You can check the release announcements here and the change log here.
I would like to highlight the significant improvement in backtracking that is part of the requirement resolver process in Pip. This process involves Pip finding a set of packages that meet your requirements and whose requirements themselves don't conflict.
For example, let's say you require packages A and B. First, the latest versions of A and B are downloaded and Pip checks their requirements, let's say Pip finds that A depends on C==2 and B depends on C==1. These two latest versions of A and B are not compatible, so Pip will try to find an older version of A and/or B where they have compatible dependencies. C in this case is called a transitive dependency because it's a dependency of a dependency.
Prior to Pip 20.3, the default process for Pip would allow conflicting requirements to install if they were transitive dependencies where the last one specified would be the one installed. This was not satisfactory for a lot of projects that had larger set of requirements because it meant package versions that did not work together could be installed
/r/Python
https://redd.it/12n5lai
Discussions on Python.org
Announcement: pip 23.1 release!
On behalf of the PyPA, I am pleased to announce that the pip team has just released pip 23.1. This is the second release of pip for the year 2023. You can read more about our versioning, deprecation policy, and release process here. Highlights Further…
what is th best practices to implement Stripe payments in a flask app
/r/flask
https://redd.it/12mszdr
/r/flask
https://redd.it/12mszdr
Reddit
r/flask on Reddit: what is th best practices to implement Stripe payments in a flask app
Posted by u/Proud_Pianist_8715 - 15 votes and 1 comment