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 use Class-based views to create a user registration?

I was wondering how can I use class based views to create a user registration because I think I can do this with a ModelForm and do all the validation in this and after using a CreateView is this correct? Or should I use an only a CreateView.

Also, if anyone has any tutorial to do this to help me understand the use of clean() on the form, how validate?

Yea, silly question :c

/r/django
https://redd.it/6vugb9
Changing a model's attribute from CharField to ForeignKey makes the object unuseable and returns "unknown NAME_id"

Say I had the following model:

class greatModel(models.Model):

attribute = models.CharField(max_length=100)

and life was good. But then another dev tells me "hey, I actually have a whole model called `attribute` in another app `HIS_APP` on this project! Just make a ForeignKey. Sounds great, so I do:

class greatModel(models.Model):

attribute = models.ForeignKey('HIS_APP.attribute', on_delete=models.CASCADE)

but now EVERYTHING I do with this model including migrations will fail on:

django.db.utils.OperationalError: (1054, "Unknown column 'attribute_id' in 'where clause'")

Any idea where I might be going wrong? I've tried dropping/remaking the model/table but that was of no use.

/r/django
https://redd.it/6vvcyq
Learning Python Is Proving To Be Hilarious

/r/Python
https://redd.it/6vrxox
Best Django books to start with?

Hi all,
I have some rookie big data py 2.7 experience. I want to get into Django and web apps and websites. Since I already has a very basic py understanding, it just makes sense to work with Django. Does anyone have any good books on amazon they recommend for beginners that really walks you through and explains concepts well?

/r/djangolearning
https://redd.it/6vvw3v
What language features makes Python positively stand out for you?

I'm curious what language features you *love* about Python that keep you coming back and make you enjoy the development experience.

For me I'd have to say a short list would be list/dict comprehension, as well as decorators.

What about you?

/r/Python
https://redd.it/6vtcdq
What hack can I do to allow me to use the algorithmicx latex extension in my notebook?

I've found exactly one answer to this topic online and it says MathJax doesn't do it.

Is there any non-portable, slightly hacky way of getting this to work? Something that would render to jpeg and embed that on the page?

/r/IPython
https://redd.it/6vxyjr
[AF][SQLAlchemy] Custom method for order_by when filtering

I'm working on a project where the user inputs a location (latitude and longitude) and the system searches the database for the closest entries by distance. However, I am unsure of how to pass a custom function (in this case, a function that calculates the distance to the provided lat/long) to the order_by method rather than by one of the fields in the database. I thought this would be a fairly common thing to implement, but I couldn't find anything helpful on StackOverflow, etc. Any help would be appreciated!

/r/flask
https://redd.it/6vwwv0
Would anyone be interested in an Electronics for Programmers book? If yes, what topics?

With an Electronics background, I sometimes struggle with software paradigms. There are a few python for engineers courses/books out there that I am looking at.

I was wondering if anyone would be interested in the opposite as well. An Electronics for CS/Programmers book/course. And if yes, what are the key areas/topics that confuse you.

Thanks.


/r/Python
https://redd.it/6w1x4z
Looking for open source Django+DRF projects that follow best practices.

The larger the project, the better. If you know of any, please give a link.

/r/django
https://redd.it/6w0hc9
Python refuses to recognize library I am almost certain exists

(i am just copying this from the stackoverflow thread that its not letting me post)

I have no idea why this is so frustrating, but I have literally pulled out a few clumps of hair in rage because this just refuses to work and I honestly do not have the slighest clue on what to do. I am trying to use the winshell module for a quick python programming I am using. I am new to python and just started trying it today. I have tried to install the library manually, and through pip. pip claims the module is downloaded, and I can see it in the `lib` folder. No matter what I do I get this error when I try to run my code:

import winshell
ModuleNotFoundError: No module named 'winshell'

what on earth must I do to get this to work I am at my wits end here and I feel like I'm going to break something

/r/Python
https://redd.it/6w4fb6
ImportError: No module named 'flask_login'

SOLVED:
My flask application isn't using the env but local machine packages, thanks guys!

/r/flask
https://redd.it/6w85r3
Auto creating URLs from user entries?

I have a website I am working on in which users can submit comments, blog entries and such. However, if a URL gets posted, it gets presented as regular text (and thus is not clickable) when the entry is posted. Is there anyway to make Django automatically make links like these clickable?

/r/djangolearning
https://redd.it/6w0p91
Anyone running a subscription site using Django and dj-stripe?

Hello!

So I've got a pretty hefty web app which is currently free and I have a bunch of people happily beta testing it. Simultaneously I've created a dev version and have implemented Stripe on it via dj-stripe. I've got it so I have plans created in Stripe, and created a plans template and view, and attached the form button for one of the plans on the plans page to the "[custom](https://stripe.com/docs/checkout#integration-custom)" implementation of Stripe Checkout. When a user clicks the button, it gives the standard Stripe Checkout pop up and the user can fill in all their data, and on the Stripe end they are attached to a subscription plan and the card is charged (test data of course for now).

Now I'm not sure where to go from here. I assume I need to somehow associate the username in the Django users database with that Stripe plan and then adjust their access accordingly but I'm not sure where to really start with this portion. The Stripe Checkout works great, but I'm not sure how to restrict user access based on which Stripe plan they're associated with. I'm sure this is going to require me to get more involved with the Django database which I am thus far unfamiliar with but I'm ready to learn!

Does anyone have any advice or could someone point me to any info that might help me get started?

Thank you!

/r/django
https://redd.it/6w7vxn