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
how to use flask with existing database

I am really quite confused about working with databases that already exist. I have followed a bunch of tutorials and read Miguel Grinberg's book, so I am familiar with the basics of how to use flask-sqlalchemy. However I have very limited database experience outside of this (aside from writing a few basic SQL commands), and the SQLAlchemy documentation completely defeats me.

Surely this is a common scenario (already have database, decide to create flask app to access it and so on), but I have never seen a tutorial anywhere that actually explains ways to handle this and now I am stuck. I do not really mind if it is with flask-sqlalchemy or with standard sqlalchemy, as long as I can do something robust.

Flask-sqlalchemy makes it reeeeally convenient to connect the app and query/insert into the table. As I understand it, this requires a set of table classes e.g. a `User` class in a `models.py` file. I know there are things like automap/reflect in the SQLAlchemy API, but I have not been able to really understand those docs sufficiently to know if I can use it with flask, and without any frame of reference it is hard to know if this is

/r/flask
https://redd.it/xwhvic
Tried to deploy my project on the internet - getting this error. What am I doing wrong?

/r/django
https://redd.it/xw42bn
400 Bad request error

This is the error I keep on getting: werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. KeyError: 'all\_chat'

And heres my code:

[app.py](https://app.py):

* Put @ app in single quotes so it won't change to a link

'@app'.route('/room', methods=\['GET', 'POST'\])
def room():
if(request.form\["all\_chat"\]):
return render\_template('chat\_all.html', session=session)
else:
return render\_template('join\_room.html', session=session)

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Chat</title>
<link href="../static/style.css" rel="stylesheet">
<link href="../static/bootstrap.min.css" rel="stylesheet">
</head>
<body class="text-center">
<form class="form-signin" action="/room" method="post">
<h1 class="mb-3 font-weight-normal">Click One of the Buttons Below</h1>
<button name="all\_chat" class="btn btn-lg btn-primary btn-block" value="submit">Join All Chat</button>
<button name="chatting\_room" class="btn btn-lg btn-primary btn-block" value="submit">Join a Room</button>
</form>
</body>
</html>

/r/flask
https://redd.it/xwtgd5
Django Docker Containers and good example projects

I am building a project that I want to deploy on a could service that requires me having a Docker image of my project.

I am new to the concept of handling multiple container at a single project ex.: Apache Airflow base Image. (I am more used to just runing a single jupyter lab in a single container)

Are there any example codes, practical docker Django guides that you would recommend so I can pick up the skill how to add nginex and js libraries to the project, etc. that I don't even think that is important now but it would help me a lot to pick up on the basic and intermediate lvl of docker with Django ?

/r/django
https://redd.it/xw7nyy
Easiest way to run Jupyter Notebooks?

I'm working on a project to develop interactive plots on jupyter notebook and would like to share them with students in the easiest way for them to run the notebooks.

I've seen lots of webs and servers that allow code to be run without installation/account creation if the proper setup is made, but I need it to be a free service (I don't really care if their PC has to run the code, but I think they'll need to install jupyter notebook then).

I'd like to know your opinion about which would be the best web/program in this situation, as I don't have much experience on this topic and there are lots of different webs that offer running jupyter notebooks as a service.

If you need a more clear statement of my preferences, they would be:

\- Needs to be free.

\- Needs to run the code (interactive figure animations).

\- Avoid as much Installation/Account creation as possible for the viewer.

/r/JupyterNotebooks
https://redd.it/wmj9vm
Jupyter Lab vs Jupyter Notebook

I currently mainly use Jupyter Notebooks because I know all the shortcut keys (a and b) to open a cell above or below and (c,v) to cut and paste simply. I like the idea of moving to JupyterLab but I miss my shortcut keys. Is there a solution for JupyterLab so that I can still use my keyboard without having to go back to using a mouse all the time?

/r/JupyterNotebooks
https://redd.it/wmcq81
Any long-run risk with sqlite?

So I'm using sqlite for the database for a record taking web app with flask. Basically, the web app takes records of people who walk into the office and such. It's all a glorified spreadsheet. Heard somewhere sqlite is limited. Wanted to know in what capacity that is.

/r/flask
https://redd.it/xx0c1s
'jupyter notebook' command doesn't work...

I'm trying to read some documentation for a course, and that's entirely in Jupyter Notebook. There's this documentation here and the very course that tell me I should just type jupyter notebook and it should run, but what I get instead is this:

PS W:\> jupyter notebook
usage: jupyter -h --version --config-dir --data-dir --runtime-dir --paths --json --debug subcommand

Jupyter: Interactive Computing

positional arguments:
subcommand the subcommand to launch

options:
-h, --help show this help message and exit
--version show the versions of core jupyter packages and exit
--config-dir show Jupyter config dir
--data-dir show Jupyter data dir
--runtime-dir show Jupyter runtime dir
--paths show all Jupyter paths. Add --json for machine-readable

/r/JupyterNotebooks
https://redd.it/wm1lzw
Is it normal for old computer to get hot when running Anaconda?

I am using an old Thinkpad.

/r/JupyterNotebooks
https://redd.it/wjrpqj
Thursday Daily Thread: Python Careers, Courses, and Furthering Education!

Discussion of using Python in a professional environment, getting jobs in Python as well as ask questions about courses to further your python education!

This thread is not for recruitment, please see r/PythonJobs or the thread in the sidebar for that.

/r/Python
https://redd.it/xwqis8
I created a simple and fast Broken Link Checker for WordPress using Python

There aren't any reliable free broken link checkers out there, so I decided to create one. Right now, it is a Python script that can be run on any platform. It is multi-threaded and has a lot of room for improvement.

Feel free to check out the code and point out the mistakes or leave suggestions. I am newbie programmer :)

https://preview.redd.it/7acdqlgha6s91.png?width=736&format=png&auto=webp&s=8bcf2ed7631513e23736dc550b64d23a24d7077d

GitHub: Suleman-Elahi/WpBrokenCheck

/r/Python
https://redd.it/xx35wf
Jupyter Notebook Competition extended!

Good news 📢
We've extended the deadline for the Jupyter \#NotebookCompetition 👏
So, if you didn't sign up yet or needed more time to complete your Notebook, you now have until 4 September!

Visit: http://notebook.wekeo.eu for more info 💻

https://preview.redd.it/scnkf9t06of91.png?width=1920&format=png&auto=webp&s=e9e2a2c0475f75d5ff2f378ddeb2b90fbb393f1a

/r/JupyterNotebooks
https://redd.it/wfx55d
Is there a reason to separate api calls into their own url endpoints?

I started a project awhile back and have made a lot of progress since then. In the beginning I didn't think much about architecture and how I'd serve data to the frontend. Now, however, it seems the way I am doing so isn't exactly like other projects I see, so here is my question.

What are the main issues with having my views formatted in such a way that when the frontend makes a request, the main view receives it and calls a function based on the action argument, rather than the frontend calling a different url endpoint? Here is an example below...

**api.py**

def to_return_stuff(request):
posts = Posts.objects.filter(~Q(user=request.user), is_active=True).order_by('-creation_date').values_list('description', 'pay', 'location', 'creation_date', 'user__username', 'pk', 'coords', 'listing_type', 'image', 'name')
posts = [p for p in posts if match(p[6], some_coords)]
return json.dumps(posts)

**views.py**

def home(request):
# page initially loads, just serving the static html, then the frontend triggers a fetch request, triggering the populate case, which serves data to

/r/djangolearning
https://redd.it/xxvwe5
Jupyter notebook is slow

I don’t think it’s my PC’s problem because every other app/website works just fine.
It has gotten really bad to the point that it takes 10 minutes to run a simple csv file.
Any help?

/r/JupyterNotebooks
https://redd.it/wcnqus