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
One-to-many relationship in Todo App

Hi, this is my first flask project. In my todo program, I'm trying to create a one-to-many relationship, such that, each user has many tasks. The issue I am facing is that every user is accessing every task in the table and I'm not sure how to fix that.

**The tables:**

class Users(db.Model):
id = db.Column(db.Integer, primary_key=True, nullable=False)
username = db.Column(db.String(20), unique=True, nullable=False)
password = db.Column(db.String(50), nullable=False)
tasks = db.relationship('Todo', backref='owner')

class Todo(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
owner_id = db.Column(db.Integer, db.ForeignKey('users.id'))

**Todo routes:**

@app.route("/tasks", methods=["GET"])
@login_required
def tasks():
"""User tasks"""
# show all todos
todo_list = Todo.query.all()


/r/flask
https://redd.it/kx2kpb
best-of-web-python: A ranked list of awesome Python libraries for web development

https://i.redd.it/jad796aqnbb61.gif

We've curated a list of the best Python libraries for web development with lots of awesome projects related to Flask!

The list is fully automated via GitHub Actions, so it will never get outdated. Every week it collects metadata from GitHub and package managers, calculates quality scores to rank projects inside categories, and identifies trending projects.

🔗 GitHub: https://github.com/ml-tooling/best-of-web-python

🎉 We also released a few other best-of lists on Reddit today:

[best-of-ml-python](https://www.reddit.com/r/MachineLearning/comments/kx8e13/p_bestofmlpython_a_ranked_list_of_awesome_machine/): Python libraries for machine learning.
best-of-python-dev: Python developer tools and libraries.
[best-of-python](https://github.com/ml-tooling/best-of-python): General overview of Python libraries & tools.
best-of-jupyter: Jupyter Notebook, Hub, and Lab projects.

📫 For updates on trending projects, new additions and detailed comparisons, follow us on Twitter or subscribe to our weekly newsletter.

/r/flask
https://redd.it/kx8mlu
P best-of-ml-python: A ranked list of awesome machine learning Python libraries

https://i.redd.it/6v5vvl7psbb61.gif

We've curated a list of the best machine learning Python libraries!

The list is fully automated via GitHub Actions, so it will never get outdated. Every week it collects metadata from GitHub and package managers, calculates quality scores to rank projects inside categories, and identifies trending projects.

🔗 GitHub: https://github.com/ml-tooling/best-of-ml-python

🎉 We also released a few other best-of lists on Reddit today:

[best-of-web-python](https://www.reddit.com/r/flask/comments/kx8mlu/bestofwebpython_a_ranked_list_of_awesome_python/): Python libraries for web development.
best-of-python-dev: Python developer tools and libraries.
[best-of-python](https://www.reddit.com/r/Python/comments/kx94kc/bestofpython_a_ranked_list_of_awesome_python/): General overview of Python libraries & tools.
best-of-jupyter: Jupyter Notebook, Hub, and Lab projects.

📫 For updates on trending projects, new additions and detailed comparisons, follow us on Twitter or subscribe to our newsletter.

/r/MachineLearning
https://redd.it/kx8e13
best-of-python: A ranked list of awesome Python libraries and tools

https://i.redd.it/n54xmlw9sbb61.gif

We've curated a list of the best Python libraries and tools!

The list is fully automated via GitHub Actions, so it will never get outdated. Every week it collects metadata from GitHub and package managers, calculates quality scores to rank projects inside categories, and identifies trending projects.

🔗 GitHub: https://github.com/ml-tooling/best-of-python

🎉 We also released a few other best-of lists on Reddit today:

[best-of-python-dev](https://github.com/ml-tooling/best-of-python-dev): Python developer tools and libraries.
best-of-ml-python: Python libraries for machine learning.
[best-of-web-python](https://www.reddit.com/r/flask/comments/kx8mlu/bestofwebpython_a_ranked_list_of_awesome_python/): Python libraries for web development.
best-of-jupyter: Jupyter Notebook, Hub, and Lab projects.

📫 For updates on trending projects, new additions and detailed comparisons, follow us on Twitter or subscribe to our weekly newsletter.

/r/Python
https://redd.it/kx94kc
[N] The White House Launches the National Artificial Intelligence Initiative Office

*What do you think of the logo?*

*From the [press release](https://www.whitehouse.gov/briefings-statements/white-house-launches-national-artificial-intelligence-initiative-office/):*

https://www.whitehouse.gov/briefings-statements/white-house-launches-national-artificial-intelligence-initiative-office/

​

The National AI Initiative Office is established in accordance with the recently passed National Artificial Intelligence Initiative Act of 2020. Demonstrating strong bipartisan support for the Administration’s longstanding effort, the Act also codified into law and expanded many existing AI policies and initiatives at the White House and throughout the Federal Government:

* The [American AI Initiative](https://www.whitehouse.gov/wp-content/uploads/2020/02/American-AI-Initiative-One-Year-Annual-Report.pdf), which was established via [Executive Order 13859](https://www.whitehouse.gov/presidential-actions/executive-order-maintaining-american-leadership-artificial-intelligence/), identified five key lines of effort that are now codified into law. These efforts include increasing AI research investment, unleashing Federal AI computing and data resources, setting AI technical standards, building America’s AI workforce, and engaging with our international allies.
* The [Select Committee on Artificial Intelligence](https://www.whitehouse.gov/wp-content/uploads/2021/01/Charter-Select-Committee-on-AI-Jan-2021-posted.pdf), launched by the White House in 2018 to coordinate Federal AI efforts, is being expanded and made permanent, and will serve as the senior interagency body referenced in the Act that is responsible for overseeing the National AI Initiative.
* The [National AI Research Institutes](https://www.whitehouse.gov/articles/trump-administration-investing-1-billion-research-institutes-advance-industries-future/) announced by the White House and the National Science Foundation in 2020 were codified into law. These collaborative research and education

/r/MachineLearning
https://redd.it/kww5nf
best-of-web-python: A ranked list of awesome Python libraries for web development with lots of Django utilities

https://i.redd.it/sdni0xd49cb61.gif

We've curated a list of the best Python libraries for web development with lots of awesome projects related to Django!

🔗 GitHub: https://github.com/ml-tooling/best-of-web-python

The list is fully automated via GitHub Actions, so it will never get outdated. Every week it collects metadata from GitHub and package managers, calculates quality scores to rank projects inside categories, and identifies trending projects.

🎉 We also released a few other best-of lists on Reddit today:

[best-of-ml-python](https://www.reddit.com/r/MachineLearning/comments/kx8e13/p_bestofmlpython_a_ranked_list_of_awesome_machine/): Python libraries for machine learning.
best-of-python: General overview of Python libraries & tools.
[best-of-python-dev](https://github.com/ml-tooling/best-of-python-dev): Python developer tools and libraries.
best-of-jupyter: Jupyter Notebook, Hub, and Lab projects.

/r/django
https://redd.it/kxb43e
Friday Daily Thread: Free chat Friday!

Use this thread to talk about anything Python related! Questions, news, projects and any relevant discussion around Python is permitted!

/r/Python
https://redd.it/kxi9jt
PyCharm users: Why do you prefer it over VSCode or other editors

After some very spirited arguments from VSCode users, I'd like to turn it around and ask PyCharm users the same thing: why do you use PyCharm and not VSCode or another modern text editor?

Is it deeper integration with language/framework features? Is it the plugin ecosystem? Or the shortcuts?

Disclaimer: I'm a PyCharm Pro user myself. ;-) But I must say, when I do anything outside of Python/Django, I use VSCode 95% of the time. Not that it's that much, but still.

/r/Python
https://redd.it/kxoflx
Django based crypto currency dashboard

Just finished a new django based crypto dashboard project that I thought this sub might enjoy. It uses Bootstrap, is hosted with Heroku and hits the CoinGecko API.

coinquote.co

/r/django
https://redd.it/kxjgr8
Uploading file on local Storage for Flask on Heroku.

I've build this web app that takes pdf file from user and store it in a folder inside my project. My code is working fine on local server. Whenever I upload file, it gets uploaded in the designated folder but when I host my app on Heroku, I'm not being able to upload file anymore. Could you please help me in figuring it? Thanks.

/r/flask
https://redd.it/kxk8rn
How to export data from JSON file to database

models.py
class Stock(models.Model):
company = models.CharField()
sector = models.CharField()
per_asset = models.DecimalField()

serializers.py
class StockSerializer(serializers)
class Meta:
fields = '__all__'

views.py
class StockAPI(generics.ListCreateAPI):
queryset = Stock.objects.all
serializer_class = StockSerializer


I scraped down the stock informations for my model, in a dictionary and dumped dictionary to a JSON output file.
This is going to be one time scraping to load the data. But I am not sure what will be the next step going forward, how can I export the data from JSON file to my Stock model database?

/r/django
https://redd.it/kxqoc9
Anyone used scipy.optimize?

Trying to get my head around the scipy optimize library and especially minimize function. Part of it is the bewildering assortment of methods like Brent and Krylow methods etc. Are their any good tutorials on using the multivariate versions of these? I am having trouble with the minimization terminating early without deviating far from my initial x0. Any thoughts?

/r/IPython
https://redd.it/kxqi4d
Tutorial: React/SPA with httpOnly Django Sessions instead of JWT Authorization

Hey all, I've created an honestly somewhat-dysfunctional tutorial on how to integrate Django httpOnly cookie sessions with React for the sake of security and avoiding stateless authorization on browsers. I couldn't find any tutorials online that included httpOnly cookies, and honestly the DSF is pretty negative against JWTs (and JS accessible session cookies...). So here's a full breakdown tutorial!

https://github.com/Andrew-Chen-Wang/SPA-with-sessions

The demo is found here: https://acwpython.pythonanywhere.com/authenticated/ When you go to the authenticated URL, you'll find your session cookie and csrftoken set. (You can change the csrftoken to also be httpOnly in the settings). Static is deployed on GitHub pages every time you update the React app and does not delete old static files in case of delays in server deployment.

Please provide feedback! Also look at issue #3 of the repo. I just have haunting memories of working on SimpleJWT (disclaimer, I'm a maintainer) + JWT Authorization integration to becoming httpOnly cookies at PR #157.

/r/django
https://redd.it/kxyudo