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
Question about jwt

I just started using `djangorestframework-jwt` and I have a few questions about it. Does a jwt get automatically created on signup/login? \(Do I need to otherwise?\). Or do my users have to manually input their credentials on a specific url to get theirs created?

/r/django
https://redd.it/8n7qsd
Questions about deploying django project to PythonAnywhere

Hi, my first time deploying to pythonanywhere (or anywhere in general) and have a few questions.

I used pipenv to create my virtual environment on my local machine and used gitlab to upload my django project and in my gitignore file, I have the sqlite database and a .env file.

I am also using python decouple to grab the environment variables and dj-database-url for my sqlite3 connection.

I just want to know if I am on the right path when deploying to pythonanywhere.

When I open their bash console, I will
* git clone <myproject url>
* pip install pipenv and activate 'pipenv shell'
* pipenv install python=3.6
* pipenv install django
* pipenv "all the different modules I imported"
* create a .env file and add my environment variables
* run python manage.py makemigrations and then migrate the database

Are there any steps I am missing? Sorry if this is such a weird question. I just want to make sure I am deploying correctly.

/r/djangolearning
https://redd.it/8n4gwn
flask/sqlalchemy without using flask_sqlalchemy

Good evening, I'm trying to figure out how to specify my database file using a flask config variable that I can alter during testing. I'm aware that I can use flask\_sqlalchemy and use the standard SQLALCHEMY\_DATABASE\_URI config, but for the sake of this conversation, I want to remove that dependency.

The piece that is failing is [https://gist.github.com/paxtontech/c2788092b31076aa6f8f22e7eb55b0a7#file\-database\-py\-L5](https://gist.github.com/paxtontech/c2788092b31076aa6f8f22e7eb55b0a7#file-database-py-L5) due to the fact that app isn't available in that context. I think I need to create an application factory, but I'm not sure how to go about setting that up while allowing the test to call init\_db with the right context as well.

Thoughts?

/r/flask
https://redd.it/8n65hy
Getting a freelancing Django job.

Ok so overall average when it comes to back end and front end. it has been six months and i already made couple of Contact/ About us to my friends and an acceptable eCommerce site.

I went and made an upwork account but every entry job listed there has a specific thing that you have to learn and i am feeling lost and have no idea what to do about that.

I mean applying for the job without the knowledge of that specific thing is unprofessional and in the meanwhile learning everything new would be a waste of time and i would never work in 3 years time so.. give me some advice my fellow djangoneers.

/r/django
https://redd.it/8n83au
[AF] troubleshooting flask app on heroku

Hi all,

I'm a newbie to web development and recently my friend and I have been trying to create a webapp that shows the count of various tweets using the TwitterAPI. We were able to create a working prototype that runs on my local machine, using flask integrated with socket\-io. Basically the point of the site is to update the count of tweets live. We tried to deploy this to Heroku but we faced some issues that we didn't exactly understand.

Basically our code has a separate script that runs the TwitterAPI stuff and the counts for various cases are saved into a SQLite database. From there, the main.py for the flask app would read the information every second and would update the site accordingly. However, when we tried to deploy this to Heroku, the database started to get overwritten: we figured out that when we used gunicorn, each HTTP request basically created a new thread and would basically run the database\-writing script multiple times, which caused problems. Currently, we don't know how to run this script once, independent from all the HTTP requests. We tried modifying the Procfile and tried different dynos but we then encountered some other bugs. Any help would be much appreciated!!

Thanks!

/r/flask
https://redd.it/8n50ot
How To Write Tests For Python

[https://able.bio/SamDev14/how\-to\-write\-tests\-for\-python\-\-22m3q1n](https://able.bio/SamDev14/how-to-write-tests-for-python--22m3q1n)

/r/Python
https://redd.it/8n7uay
How to exclude database password when pushing to github?

Hiho, today I setup a Djangoproject, and for the first time I`m using PostgreSQL instead of SQLite. Everything is great and setting it up, unexpectedly, was no problem.
But now I would like to know if there is a way to exclude the databasepassword from the settings.py file when I push the project to github. I know how to exclude the whole settings.py file with .gitignore, but thats not really what I would like to do.

Thats the part for the database.

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django',
'USER': 'me',
'PASSWORD': 'passwort',
'HOST': 'localhost',
'PORT': '',
}
}


/r/django
https://redd.it/8n8oj0
Using python manage.py shell effectively

When using django shell, i have to enter all the imports manually, and also rewrite the views for testing. This is so much of work and also a pain in a\*\*. Is their any way where i have to type less and test more. Like any tip on how to use django shell effectively.

/r/django
https://redd.it/8n8x3w
Alternative for php's include/require function in Django

[SOLVED]
Hi, I am new to django, I used to use php but now I have to work on a quite big project I have decided to use django. In php I used to reuse code using include function. eg. if there is a navbar that needs to be displayed on top of every page in the website, instead of writing html for navbar on every page I used to write it in a seperate file called `navbar.php` and the use

include('/navbar.php');

on appropriate places in every webpage.
How do I implement this in django. I looked into creating a base.html and extending it but its not quite the same.

/r/django
https://redd.it/8n6mob
Need Help With VCS/Deploying (details in description)

I've written a REST API with Django Rest Framework. I want to keep the project on a private github repo. However, I've heard that it is a bad idea to keep settings.py in version control. I've overidden the secret variables with a local_settings.py file that will be used to hold production config variables that is gitignored. However, I'm not sure how I push local_settings.py to Heroku when deploying with Heroku Git, but keep local_settings.py out of the private github repo. Furthermore, how should I manage database setup (using sqlite3 in production for now)?


I am also using Gunicorn if this is relevant.

/r/django
https://redd.it/8nf7z7
Dear Python, where have you been all my life?

I am NOT a developer. But, I've tinkered with programming (in BASIC, Visual Basic, Perl, now Python) when needed over the years, starting in my teens during the 80's and throughout my career, and had at least entry level courses in COBOL(in about 1990), C, and Java (in about 2009) while getting my degree. (I was somewhat of a nontraditional student.)

Today I decided that I needed to script something, and hoped that *learning* how to do it in Python was going to take me significantly less time than doing it manually - with the benefit of future timesavings.

No, I didn't go from 0 to production in a day. But if my coworkers will leave me alone, I *might* be in production by the end of the day tomorrow.

The last thing I used to scratch an itch like this was Perl in about 2013. Like with Python, I was learning as I went. And in that case - while some parts weren't bad, other parts were like running barefoot over sharp glass. I have working Perl from back then that I still don't *quite* understand bits of, because the best I could do is take someone else's example and massage it for my needs in some places. (In fairness, what I was doing there was a bit more complex, but it still wasn't rocket science.)

What I'm working on today isn't super complex - I'm taking some user input, making some decisions based on that input, reading a .csv, and will ultimately output a json file - but I've been able to easily understand everything I've done so far. I've done a bit of googling around the json and csv bits, and that seems pretty easy too. But putting together what I've done so far has just been a complete joy.

The syntax is so wonderful - it took me a couple of minutes to realize, for instance, that there was no "wend" or similar for a "while" loop, that merely the end of a code block would serve the same purpose. But when I did I immediately thought "wow, of course not - how efficient is that?" I feel like that's a big part of what I'm enjoying - things that maybe should be able to be implied rather than explicitly typed in or stated, actually *are* implied in many cases. It feels like there's a lot less in the way of required punctuation, that's for sure.

Overall it feels natural, intuitive, and relatively easy to understand and write the code for the basic things I'm doing - I haven't had this much fun doing stuff with code since the days fooling around with BASIC in my teens.

Well, thanks if you actually read this far. I've just found this to be so fun and exciting I had to share it with folks who might care. I think I'm going to be looking for excuses to script things with Python going forward. :-)





/r/Python
https://redd.it/8ndhel
I made a FTP/SFTP client using python and tkinter

/r/Python
https://redd.it/8niot2
ldap authenticator for jupyterhub

Hello all!

Long time lurker, first time poster.

I recently created a new ldap authenticator for jupyterhub geared more towards enterprise ldap integration. It includes support for the following features:

- Multiple LDAP servers
- Nested groups
- User home directory creation at login

Any feedback would be much appreciated. Please let me know what you think!

github: [jupyterhub-ldap-authenticator](https://github.com/hansohn/jupyterhub-ldap-authenticator)
pypi: [jupyterhub-ldap-authenticator](https://pypi.org/project/jupyterhub-ldap-authenticator/)

/r/IPython
https://redd.it/8nlh3e
Sentry is pretty popular with Django because it's mentioned in the django docs, so I wanted to ask how you're all dealing with GDPR?

I'm a bit confused on what I need to do to be able to use sentry with Django so I don't get in trouble with ico because of gdpr.


They wrote a blog post here about: https://blog.sentry.io/2018/03/14/gdpr-sentry-and-you


But I'm still kinda confused after reading it.


And GDPR is supposed to be OPT IN instead of OPT OUT, right? But if you've already given your users cookies and sent their data to sentry the first moment they connect to your site, regardless if you have a banner on the top of the screen that says "You have to agree to use cookies if you want to use this website" but they haven't agreed to anything and they received those cookies before the banner showed up.


And I see that ICO is constantly handing out huge fees nonstop to companies all day long, they just don't run out of companies to fine. They really hit jackpot with this new law. You can see every company they've taken action against on ico's website.

/r/djangolearning
https://redd.it/8nm2oz
So hypothetically speaking, what should I do to learn python as much as possible before a job interview this Tuesday

Hypothetically speaking ofc

I have no previous experience with python, only SPSS, Excel and some R knowledge. No high level of python is needed, just the basics and maybe some more.

/r/Python
https://redd.it/8nno08
Moving from Java to Python?

So I'm a high school student with experience in Java up through the AP Computer Science level, and I want to learn Python in order to work with grad students at my local university. Where should I start?

/r/Python
https://redd.it/8no5bd