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
Having to stop Flask server to run other functions.



I'm currently trying to make a simple flask server that gets input from the local frontend, uses the input to get certain data from a CSV, and then send the data back to the frontend. (I'm brand new to python and web development).

The issue that I'm having is this:

When I run the program, it starts the server and I go onto the frontend and post the input to the backend. It then stores the input in a variable.

I then have to manually stop the server by pressing ctrl-c. This then allows the code after it to run. (The function to get data from the CSV).

Do I then have to automatically restart the server to then send the data to the frontend? This just seems too complicated, and I've been told that you can do all this without stopping the server at all in the first place. I heavily get the sense that I'm missing the trick somewhere, however I'm new to this so pls understand :).

Please let me know if the above makes no sense and I'll try to rephrase.

/r/flask
https://redd.it/xe46js
Making Jupyter notebooks more SQL-friendly?

As a data scientist, I spend a lot of time preparing SQL queries, usually in a Jupyter notebook; however, I feel the experience isn't smooth. After a few days of beginning some analysis, my notebook is full of copy-pasted SQL chunks and a weird mix of SQL and pandas.

Sometimes I use the [ipython-sql](https://github.com/catherinedevlin/ipython-sql) extension, allowing me to write simpler code than [pandas.read\_sql](https://pandas.pydata.org/docs/reference/api/pandas.read_sql.html). However, I think some features would come in handy.

Here's my wishlist:

* Facilitate writing large queries
* Choosing plotting backends like matplotlib, plotly, etc.
* Plot computation by the SQL engine

Anything I'm missing? What would it make a smooth SQL experience in Jupyter notebooks for you?

/r/IPython
https://redd.it/wb5fwh
3 models union function mixing up values

so I have this function



`def all(request):`
`movie = List.objects.all()`
`music = MusicList.objects.all()`
`book = BookList.objects.all()`

`a = movie.union(music)`
`allPosts = a.union(book)`

`# allPosts = List.objects.filter(title__search=query)`
`params = {'allPosts' : allPosts}`
`return render(request, 'app/all.html', params)`

All 3 models have same fields

​



`class List(models.Model):`
`title = models.CharField(max_length=65)`
`author = models.ForeignKey('Author',on_delete=models.SET_NULL,null=True)`
`genre = models.ManyToManyField('Genre')`
`posted = models.DateTimeField(auto_now_add=True)`
`content = RichTextField(null=True,default=' ')`
`type = models.CharField(max_length=10,default="Movie")`



`class BookList(models.Model):`
`title = models.CharField(max_length=65)`
`author = models.ForeignKey('Author',on_delete=models.SET_NULL,null=True)`
`genre = models.ManyToManyField('BookGenre')`
`posted = models.DateTimeField(auto_now_add=True)`
`content = RichTextField(null=True,default=' ')`
`type = models.CharField(max_length=10,default="book")`

​

and so on

​

in my template



`<div class="thumb">{{allPosts}}</div>`
`{% for lola in allPosts %}`
`<div class="elements">`
`<div class="thumb">`
`<img src="{% static 'app/images/movie-poster.jpg' %}" width="100px" />`
`</div>`
`<div class="Title">`
`{% comment %} <a href="{{lola.id}}/"><h4 class="tit">{{lola.title}}</h4></a> {% endcomment %}`
`<a href="{{lola.id}}/"><h4 class="tit">{{lola.title}}</h4></a>`
`</div>`
`<div class="Author">`
`<small>Author : {{lola.author}}<span>{{lola.posted}}</span></small>`
`</div>`
`<div

/r/django
https://redd.it/xe9bjo
How do I integrate Django rest with ckeditor?

Does anybody know a good tutorial that explains how to integrate Django rest Framework with ckeditor (or any similar editor). I am making a RESTfull API to be consumed with react. I would like to edit blog posts on Django Admin then use the endpoints in react. I have been googling for the same but I can not find a tutorial. Here's the project if you wanna look around. Thanks.

/r/django
https://redd.it/xea042
how to correct this error?

I want to show whether those who scored lower will have lower salary than those who scored higher.

https://preview.redd.it/yyenlky6e8e91.png?width=883&format=png&auto=webp&s=345422026e344d1cb24afdb33773d3999eebe63f

/r/IPython
https://redd.it/w9z77l
Machine Learning from Scratch with Python

Hey everyone!

I've seen a growing number of people looking for resources on how to implement Machine Learning algos from scratch to better understand how they work (rather than just applying e.g. sklearn).

This free **Machine Learning from Scratch Course** on YouTube takes you through writing 10 algorithms from scratch with nothing but Python and NumPy! The algorithms are:

1. K-Nearest Neighbors
2. Linear Regression
3. Logistic Regression
4. Decision Trees
5. Random Forest
6. Naive Bayes
7. PCA
8. Perceptron
9. SVM
10. K-Means

Hopefully some of my Python + ML friends will find this helpful! :)

/r/Python
https://redd.it/xe2mzy
Xarray variables

Is there any way to see xarray variables on variable inspector?

Thanks in advance.

/r/JupyterNotebooks
https://redd.it/xd2dg5
What kind of subplots is the best?

&#x200B;

https://preview.redd.it/pf4doyu36xd91.png?width=1234&format=png&auto=webp&s=903c951f219a64964871611a54462825e00435eb

Tried using the codes below but it is not the kind i wanted. I wanted 4 subplots with the xaxis as 'salary' or is there other way to show it?

plt.figure(figsize=(14,8))
sns.pairplot(df['ssc_p','hsc_p','degree_p','etest_p'], kind="reg")

/r/IPython
https://redd.it/w8kplp
Argument parsing/validation for flask?

Is there a way with flask to create some sort of argument serializer deserializer?

I really like in django how you can specify a serializier that take a requests urlparams/body and tells you which fields are correct, which are required and what format they need to be in.

I was hoping there might be an equivalent for endpoints that don't directly use a sqlalchemy/marshmallow serializer

thanks for any help!

/r/flask
https://redd.it/xe9r5v
CI/CD Django How to make this work: push to GitHub > run GitHub action (tests) > auto deploy app if tests passed?

Hello guys,

I'm new in CI/CD and not-so-experienced in Docker. Right now I have my Django project deployed on DigitalOcean droplet and every time new code is pushed to GitHub, after GitHub action that runs tests automatically, I need to deploy the project manually.

I'm trying to figure out how to make this flow automatic.

This is what I want:

1. push to master (manually)
2. run tests on master (auto)
3. automatically deploy app (auto) if tests passed

I'm considering DigitalOcean Apps platform but the code would be deployed even before the tests passed.

I'm also considering Dockerizing the app but I'm not sure how that would help.

&#x200B;

Can you give me some advice? How would you do that?

&#x200B;

Thanks

/r/django
https://redd.it/xecxo5
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/xehfdb
Deployment - After setting up Gunicorn, Nginx and turn DEBUG = False, how do you update your code?

Is this done through your VPS service (digitalocean, vultr, aws, etc.) ? I am still in my local environment and I have a self-signed HTTPS cert set up so I can "see" what my project will look like without running Django's built-in server. Everything looks good but I wanted to change a couple of things (css, html in the templates, and some of my backend logic in the views.py) but none of my changes have taken effect.

I have:

cleared my browsers cache, restarted Gunicorn and Nginx service, none of it worked. It's almost as if Gunicorn and Nginx have a snapshot of my web app and cannot see any updates that I make.

Any help would be greatly appreciated.

/r/django
https://redd.it/xero8v
Real-time glucose updates on Discord

I made a small python script to read your glucose level and update your discord 'playing status' accordingly. Also displays a quote based this value.

Here's a link to the Github. Make sure to give some feedback.

This script uses the API of the external LibreLinkUp app and sents some HTTP requests to retreive glucose data.
It also uses qwertyquerty's Pypresence to update Discord's 'Currently playing status' in which the glucose level and other data is shown.

&#x200B;

Example of my blood sugar being a little high after a meal.

&#x200B;

Another example. This time it is on a good value.

I am planning on running this on my raspberry pi at home so it will update constantly.

It was a very fun little project to work on!

By the way, if you got some fun quotes, make sure to post them in the comments and I might add them.

/r/Python
https://redd.it/xf0i8c
How to auto-grading a exam on a website?

Hi all,


I'm helping a friend to improving his website. He is running a educational website for school kids. On that site kids are required to do exams for certain subjects. He wants to to improve the website by having a automatic grading system so he can skip grading by hand. Do you have any idea how to do that? Or is this even a backend problem? Some creative solutions?


The exams consist multiple choices, fill in the blanks, and some questions you have to hand drawing the solutions. For example draw force diagram graph in physics. Which i think it's quite impossible.

/r/Python
https://redd.it/xffxqe
GeoDjango - Can someone explain the difference between PostgreSQL and PostGIS?

SOLVED!

Please see the current state of this problem at the link below to the new thread

https://old.reddit.com/r/django/comments/xftmkr/geodjangoround2setupcompletestrugglingto/?

-----

I have a form which accepts a five digit zip code.

This should return a list of all models with a zip code field within x miles radius of the submitted zip code.

I have been informed that this is possible with GeoDjango. I am following the GeoDjango tutorial here: https://docs.djangoproject.com/en/4.1/ref/contrib/gis/tutorial/

Now in the first steps, it appears that I'm all the sudden supposed to replace PostgreSQL under "Databases" in settings.py with PostGIS.

First off, I'm not excited about losing literally all of my data.

Second, can anyone explain briefly what the difference is between the two? The only reason I'm using PostgreSQL is because I've been specifically told that if you are deploying a Django website to production, PostgreSQL is indisputably the way to go every single time. Something about being able to handle a shitload of requests and be able to scale easily. I think Heroku also may or may not require it.

Anyways, am I actually supposed to kill PostgreSQL?

/r/django
https://redd.it/xfso52
[D] Machine Learning - WAYR (What Are You Reading) - Week 140

This is a place to share machine learning research papers, journals, and articles that you're reading this week. If it relates to what you're researching, by all means elaborate and give us your insight, otherwise it could just be an interesting paper you've read.

Please try to provide some insight from your understanding and please don't post things which are present in wiki.

Preferably you should link the arxiv page (not the PDF, you can easily access the PDF from the summary page but not the other way around) or any other pertinent links.

Previous weeks :

|1-10|11-20|21-30|31-40|41-50|51-60|61-70|71-80|81-90|91-100|101-110|111-120|121-130|131-140|
|----|-----|-----|-----|-----|-----|-----|-----|-----|------|-------|-------|-------|-------|
|[Week 1](https://www.reddit.com/4qyjiq)|[Week 11](https://www.reddit.com/57xw56)|[Week 21](https://www.reddit.com/60ildf)|[Week 31](https://www.reddit.com/6s0k1u)|[Week 41](https://www.reddit.com/7tn2ax)|[Week 51](https://reddit.com/9s9el5)|[Week 61](https://reddit.com/bfsx4z)|[Week 71](https://reddit.com/d7vno3)|[Week 81](https://reddit.com/f1f0iq)|[Week 91](https://reddit.com/hlt38o)|[Week 101](https://reddit.com/k81ywb)|[Week 111](https://reddit.com/myg8sm)|[Week 121](https://reddit.com/pmzx3g)|[Week 131](https://reddit.com/srsu2n)||||||||||||
|[Week 2](https://www.reddit.com/4s2xqm)|[Week 12](https://www.reddit.com/5acb1t)|[Week 22](https://www.reddit.com/64jwde)|[Week 32](https://www.reddit.com/72ab5y)|[Week 42](https://www.reddit.com/7wvjfk)|[Week 52](https://reddit.com/a4opot)|[Week 62](https://reddit.com/bl29ov)|[Week 72](https://reddit.com/de8h48)|[Week 82](https://reddit.com/f8fs6z)|[Week 92](https://reddit.com/hu6zq9)|[Week 102](https://reddit.com/kh27nx)|[Week 112](https://reddit.com/n8m6ds)|[Week 122](https://reddit.com/pw14z5)|[Week 132](https://reddit.com/t2xpfe)||
|[Week 3](https://www.reddit.com/4t7mqm)|[Week 13](https://www.reddit.com/5cwfb6)|[Week 23](https://www.reddit.com/674331)|[Week 33](https://www.reddit.com/75405d)|[Week 43](https://www.reddit.com/807ex4)|[Week 53](https://reddit.com/a8yaro)|[Week 63](https://reddit.com/bqlb3v)|[Week 73](https://reddit.com/dkox1s)|[Week 83](https://reddit.com/ffi41b)|[Week 93](https://reddit.com/iaz892)|[Week 103](https://reddit.com/kpsxtc)|[Week 113](https://reddit.com/njfsc6)|[Week 123](https://reddit.com/q5fi12)|[Week 133](https://reddit.com/tdf2gt)||
|[Week 4](https://www.reddit.com/4ub2kw)|[Week 14](https://www.reddit.com/5fc5mh)|[Week 24](https://www.reddit.com/68hhhb)|[Week 34](https://www.reddit.com/782js9)|[Week 44](https://reddit.com/8aluhs)|[Week 54](https://reddit.com/ad9ssz)|[Week 64](https://reddit.com/bw1jm7)|[Week 74](https://reddit.com/dr6nca)|[Week 84](https://reddit.com/fn62r1)|[Week 94](https://reddit.com/ijjcep)|[Week 104](https://reddit.com/kzevku)|[Week 114](https://reddit.com/ntu6lq)|[Week 124](https://reddit.com/qjxfu9)|[Week 134](https://reddit.com/tpruqj)||
|[Week 5](https://www.reddit.com/4xomf7)|[Week 15](https://www.reddit.com/5hy4ur)|[Week 25](https://www.reddit.com/69teiz)|[Week 35](https://www.reddit.com/7b0av0)|[Week 45](https://reddit.com/8tnnez)|[Week 55](https://reddit.com/ai29gi)|[Week 65](https://reddit.com/c7itkk)|[Week 75](https://reddit.com/dxshkg)|[Week 85](https://reddit.com/fvk7j6)|[Week 95](https://reddit.com/is5hj9)|[Week 105](https://reddit.com/l9lvgs)|[Week 115](https://reddit.com/o4dph1)|[Week 125](https://reddit.com/qtzbu1)|[Week 135](https://reddit.com/u0pnhf)||
|[Week 6](https://www.reddit.com/4zcyvk)|[Week 16](https://www.reddit.com/5kd6vd)|[Week 26](https://www.reddit.com/6d7nb1)|[Week 36](https://www.reddit.com/7e3fx6)|[Week 46](https://reddit.com/8x48oj)|[Week 56](https://reddit.com/ap8ctk)|[Week 66](https://reddit.com/cd7gko)|[Week 76](https://reddit.com/e4nmyk)|[Week 86](https://reddit.com/g4eavg)|[Week 96](https://reddit.com/j0xr24)|[Week 106](https://reddit.com/ljx92n)|[Week 116](https://reddit.com/odrudt)|[Week 126](https://reddit.com/r4e8he)|[Week 136](https://reddit.com/ub2xlz)||
|[Week