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
django chart.js - Query to count all distinct values for particular colum

My goal is to create a query to group together unique 'charges' and count them. Then correctly implementing a for loop, the goal is a pie chart showing multiple slices, each individual slice showing the total count per unique charge.

Currently here is the pie chart https://imgur.com/a/11TLOdC
I would like this to instead show 1 large slice for DUI (2/3) and 1 small slice for Assault (1/3). I think its my query that needs revising, any insight would be appreciated.

# Models.py
class Arrest(models.Model):
number = models.IntegerField()
date = models.DateField()
charge = models.CharField(max_length=64)

# Views.py
def visuals(request):
data = []
labels = []
# Currently my query and maybe the root of the issue
queryset = Arrest.objects.annotate(Count('charge'))

for arrest in queryset:


/r/djangolearning
https://redd.it/iltvaw
Creating a pastebing using Flask

Hello, I am trying to use Flask and thought that a fun way to do that would be to try to implement a pastebin (something like [this one](https://dpaste.com/)) hosted on my own computer. I have started with this [tutorial](https://www.roytuts.com/upload-and-display-image-using-python-flask/) where I learned how to create a website on which I can upload images. Now I want to modify it such that a new sub-website is created everytime I upload an image, like a pastebin. But I have no idea how to do that. Could someone help me figure it out?

/r/flask
https://redd.it/ilwecp
R kernel Jupyter nightmare

Hi thank you for your time,

macOS Catalina Version 10.15.6

2013 Macbook Air

I want to preface this post by saying two things.

1: I am trying to get this program up and running for school and have tried everything I know and understand how to do over the last 2.5 days.

2: Although I followed the instructions of the official IR installation route my computer did not recognize the package and just kept telling me it didn't recognize the phrase IRkernel or irkernel or almost anything else I tried. However, I do have R set up through the R developers download and through Anaconda. So I'm sorry if this isn't the appropriate forum for this but I really don't know where else to turn.

The basic issue I'm having is that I cannot get a jupyter notebook to run my R kernel, it just keeps saying connecting to kernel endlessly and will not allow me to run any code. I have included some screenshots of my jupyter notebook and my terminal window below.

​

https://preview.redd.it/i9dxi6ymqyk51.png?width=1417&format=png&auto=webp&s=6cddae1a1235972d23d3e5fde942c75f28c22996

https://preview.redd.it/lyao4fymqyk51.png?width=1440&format=png&auto=webp&s=48e705030ec4b4e58283af39847b02643d074775

/r/JupyterNotebooks
https://redd.it/ilxbdq
Dynamic drop down list in Django admin

Hey guys, how is it possible to create a dynamic drop down list in Django admin for exemple country and city. Let’s say you have a model for an event, and you have to chose the country and the city from which the event is taking place in Django admin, and making sure once the country is selected, we will have the specific cities related to that country. It would have been easier if it had to let the end sure fill out that form in a template, but I’m still trying to see how this can be done in the Django admin page. Thanks already for your helps.

/r/django
https://redd.it/im0ivs
Django & SEO in digital Marketing

So I recently joined digital marketing company. They hired me for a developer position and ask me to develop seo website, they've been developing website using wordpress but I don't know nothing about wordpress so I told them I can try using django so can anyone tell what approach should I take ?

Please go easy on me I just started learning django, so basically I'm not beginner but also don't have deep understanding in django.

/r/django
https://redd.it/ilwek2
Friday megathread: 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/im59pd
Symple Data - data the symple way

Hi there,

[this](https://www.symple-data.com/) is a new platform/website for user specific data. We've found that, unlike well known datasets (e.g. weather, population,...), this type of data is not easy to find and/or not free. Help us grow if you agree with us as the value of [this](https://www.symple-data.com/) site grows with its userbase. Visit r/symple_data to post your thoughts or comment below!

/r/flask
https://redd.it/ilz8ws
AutoScraper: A Smart, Automatic, Fast and Lightweight Web Scraper for Python

In the last few years, web scraping has been one of my day to day and frequently needed tasks. I was wondering if I can make it smart and automatic to save lots of time. So I made AutoScraper!

The project code is available on Github: [github.com/alirezamika/autoscraper](https://github.com/alirezamika/autoscraper/)

This project is made for automatic web scraping to make scraping easy. It gets a url or the html content of a web page and a list of sample data which we want to scrape from that page. **This data can be text, url or any html tag value of that page**. It learns the scraping rules and returns the similar elements. Then you can use this learned object with new urls to get similar content or the exact same element of those new pages.

I hope this project is useful for you and saves your time, too.I look forward to hear any feedback or suggestion.

/r/Python
https://redd.it/im6u4b
html syntax in flask

Hiii

I am new to this, I am trying to read an html file with render\_template in my python file(I put it in the right folder), but when I run it and go to the local host I see that the html file hasn't been translated, am I missing something ?

thanks in advance

https://preview.redd.it/u2pgfhz4btk51.png?width=1296&format=png&auto=webp&s=d84be80cedf538dbbc981cae1df1a37ec70fd882

/r/flask
https://redd.it/ilh2tc
How to delete 4 spaces at once?

Sometimes IPython autoindents with extra 4 spaces which I don't want. For deleting the extra indent, I have to press backspace 4 times. Is there any better way to do that?

/r/IPython
https://redd.it/imc2it
Learn how to build a simple Twitter clone using Django and Vue.js (3 hours+)

I love to create tutorials where I can help more people get into programming. The newest video tutorial I have created is called "Learn how to build a simple Twitter clone using Django and Vue.js" and it is around 3 hours long. It thought about doing a series like I have done earlier, but wanted to make one long video instead this time.

​

During this video, you will learn how to build a simple twitter clone / a simple social network. Some of the cool functionality I can mention is following users, direct messages, notifications and feed. You will learn a lot of Django in this video, but I have also used Vue.js to talk to the backend, for validation etc.

​

Here is a list of "tasks" I will go through during this video:

\-Setup and create project
\-Create folders for structure and similar
\-Create app for core views, oinks, userprofiles, notifications
\-Create base html files
\-Create front page with some information
\-Create login and signup page
\-Create page for "my feed"
\-Make it possible to sign out
\-Make it possible to write an oink (Vue.js - Submit and append to list)
\-Make

/r/django
https://redd.it/im9h8n
Implementing JWT Authentication

A DRF beginner here. I'm building a RESTful API using DRF and [`dj-rest-auth`](https://github.com/jazzband/dj-rest-auth). The [docs](https://dj-rest-auth.readthedocs.io/en/latest/installation.html#json-web-token-jwt-support-optional) provides a brief guideline on how to use JWT authentication. It seems like dj-rest-auth is implementing JWT authentication through another package, [`django-rest-framework-simplejwt`](https://github.com/SimpleJWT/django-rest-framework-simplejwt).

The confusing part of this is that SimpleJWT has its own [docs](https://django-rest-framework-simplejwt.readthedocs.io/en/latest/getting_started.html#installation) which explains how one might go about setting up a basic JWT authentication.

The question boils down to this: should I use `"dj_rest_auth.jwt_auth.JWTCookieAuthentication"` or `"rest_framework_simplejwt.authentication.JWTAuthentication"` for my authentication backend? I've tried both, and it seems like they both return the same response, *i.e.* a pair of access and refresh tokens.

I've looked at the [source code](https://github.com/jazzband/dj-rest-auth/blob/master/dj_rest_auth/jwt_auth.py) for dj-rest-auth's JWT authentication backend and have verified that its JWT backend inherits from SimpleJWT's own authentication backend. dj-rest-auth's backend seems to add something related to CSRF. As the team is planning to build a completely decoupled frontend and backend living in subdomains (*e.g.* api.domain.com and www.domain.com), I'm not sure what mode of authentication would be the most optimal.

Thanks in advance for the help and advice!

/r/django
https://redd.it/imda8k
Learn how to build a simple Twitter clone using Django and Vue.js (3 hours+)

I love to create tutorials where I can help more people get into programming. The newest video tutorial I have created is called "Learn how to build a simple Twitter clone using Django and Vue.js" and it is around 3 hours long. It thought about doing a series like I have done earlier, but wanted to make one long video instead this time.

During this video, you will learn how to build a simple twitter clone / a simple social network. Some of the cool functionality I can mention is following users, direct messages, notifications and feed. You will learn a lot of Django in this video, but I have also used Vue.js to talk to the backend, for validation etc.

Here is a list of "tasks" I will go through during this video:

\-Setup and create project
\-Create folders for structure and similar
\-Create app for core views, oinks, userprofiles, notifications
\-Create base html files
\-Create front page with some information
\-Create login and signup page
\-Create page for "my feed"
\-Make it possible to sign out
\-Make it possible to write an oink (Vue.js - Submit and append to list)
\-Make it

/r/djangolearning
https://redd.it/im9hyx
Best Deployment Options for 5 Domains?

I've got three sites ready to deploy, with two more that will be ready in a few months.

What is the cheapest options for doing this without the obvious Heroku, Github, etc?

/r/django
https://redd.it/imjaxr
What's the best way to save files?

I decided to make a website in which certain users can upload files and others users can download them. I saw a video by pretty printed in which he converted the file to bytes and save them to a database but I ended up not doing it that way. I made a folder for the files and saved them there with the `os` module by following [this](https://flask.palletsprojects.com/en/1.1.x/patterns/fileuploads/). Now I'm thinking of making another website that involves saving images, so how should I save images?

Sorry if my English was bad.

/r/flask
https://redd.it/imh5wn
Saturday megathread: Share your resources!

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/imr8h6
Discrepancy in logging output between IDLE and Terminal

import flask

app = flask.Flask(__name__)

@app.route("/")
def about():
return hello

if __name__ == "__main__":
app.run(debug=True)

When the code is executed and I visit [http://localhost:5000/](http://localhost:5000/) , I get a NameError exception page from the debugger, which is expected. However, the stderr output in the shell differs:

IDLE

================= RESTART: /Users/eExamSystem/Documents/app.py =================
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat

IDLE Without Debugger (For comparison)

================= RESTART: /Users/eExamSystem/Documents/test.py =================
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[2020-09-05 17:57:38,774] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)


/r/flask
https://redd.it/imylhc
I made a Spotify ad stopper because I was too poor for Premium. It automatically detects when an ad plays and then restarts Spotify in the background. It's my first project after escaping tutorial hell and I'd love any feedback you guys have!

It detects when an advertisement plays by monitoring the type of what track is currently playing, using the Spotipy api. It then closes and opens Spotify by the os module and plays it via pynput.

There have been a few programs in this subreddit which offer a similar functionality but mute spotify, and play another locally-stored song. I preferred not using that method and hence did this.

The code is present below, and is also present in my github repo [here](https://github.com/SakDev/SpotiByeBye).

Once again, I truly would appreciate any constructive feedback!

**Edit**: Thank you so much for your positive response!!!! I've added a readme file to help anyone understand the gist of setting up the Spotify API to get your Client ID and secret.

And to all the people who claim this is stealing, I just wanted to say that while it does test ethical bounds, this program merely restarts Spotify using legally-obtained data from Spotify. Chill dude.

​

https://preview.redd.it/prkuja5q6cl51.png?width=4560&format=png&auto=webp&s=36f824adc24665e71d497aeb7e8afde5b1f2e9f7

/r/Python
https://redd.it/in1pyu
What are the uses of vue.js and react with django ? How they are useful in django ?

Right now i am learning django. I know basics about python. I see many tutorials about django+react and django+vue.js for making webapps but I want know when to use vue.js or react with django.

/r/django
https://redd.it/in3jvb
Sunday megathread: 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/inbwja