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
Concerned about using Django

Hi,

My background is in PHP (It serves me well) and I use it primarily at work, however I've been learning Python and Django at home and am really enjoying using them and would like to start using them for work, but I just have a few concerns about deployment.

My main concern is portability I suppose. For example if I created a CRM system that could be distributed like WordPress this would be fairly simple in PHP as almost every host supports it and if a client already pays for hosting on servers my company doesn't use then I can just upload the files and the application would work. Is this ease of use doable with a Django application? From what I gather there is a lot of additional configuration required, and as I say if the final environment is out of my hands then I'd rather use something that I know will work.

I have considered just using PHP for work and Django for my own side projects, but I'm really like the Python language and the Django framework so if I could use them on projects at work that would be really cool.

Thanks in advance.



/r/django
https://redd.it/7bvo4g
[AF] Performance penalty for jinja_env.globals? Any other reason not to do it?

I occasionally run into situations where Jinja is missing a few import Python functions, like len(), or even some of my own. So I've been making liberal use of jinja_env.globals to sneak some of those functions into my templates.

Is there any reason I shouldn't do that? It feels like cheating and it is rubbing my Catholic childhood wrong. Anything this quick and easy must be bad, and will surely damn me for eternity.

/r/flask
https://redd.it/7bvxnl
Django best practices to pass user groups to client side

Hey Django devs!

 

I'm fairly new to django, I'm currently building an app that has users that belong to different groups, the client side app has different behavior depending on the user groups, so all the scripts on the site should be able to figure out to what groups the user belongs to. I'm currently dynamically adding the groups to a script with a global scope so that all other scripts can access the groups, but I feel like there has to be a better way to do this, any ideas? Any way to store those values in a cookie from django and then accesing it with the js?

/r/django
https://redd.it/7bucao
Settings.py for sending emails

Rather new to programming. I want to set up a simple form which will send it's content to an admin's email. What I'm failing to understand is what happens in settings.py. I have:

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'name@gmail.com'
EMAIL_HOST_PASSWORD = 'password' #
EMAIL_PORT = 587
EMAIL_USE_TLS = True

My questions are:

1. Is EMAIL_HOST_USER referring to the admin's email?
2. In EMAIL_HOST_PASSWORD should I write the password with which the admin connects to his email (related to this, I've found a suggestion for gmail accounts to use [DisplayUnlockCaptcha](https://accounts.google.com/DisplayUnlockCaptcha), added a new app, and a code was generated. Must that be copy-pasted at EMAIL_HOST_PASSWORD?)
3. What's with the EMAIL_PORT? How do I know which one works for me?

/r/djangolearning
https://redd.it/7bh60t
I eventually want to port my Django web site/app over to mobile. Is it necessary that I incorporate DRF ASAP?

It'll be for both the browser and mobile.
I decided browser first, though, since I've already invested quite a bit of time into it.
From my understanding, adding an API using DRF would *not* mean a complete rewrite of my current class-based-view django app. Instead, it only means an addition of new code--"api" folder, serializers, new url routes, etc.


Is this actually the case? Can I freely continue working on the browser version and simply add DRF for mobile later down the line?
If so, how does this change if I decide to add a frontend framework to my browser such as React?
React may also be frontend framework of choice for mobile given React Native.

But if this isn't the case, should I have started with DRF? What considerations should I make now to ensure that the eventual browser-mobile porting works out?

/r/django
https://redd.it/7bz6vc
Django UnboundLocalError when submitting an empty form

Hello, I'm new to django and I'm trying to build something. I made a form for users to comment on a post and it works well but when I tried to submit the form without any content there was a big error on the screen which says I've referenced a local variable before assignment. Can anybody tell me how to fix that?? I'll be very thankful.

/r/djangolearning
https://redd.it/7c00ry
A Python library for particle swarm optimization

Hi! Few months ago I shared a very simple project in this sub, and thanks to your suggestions and comments, I learned a lot and was able to transform (or "overhaul") it into a full package. First off, thank you very much!

I would like to present [PySwarms](https://github.com/ljvmiranda921/pyswarms), a Python library for particle swarm optimization. Aside from performing basic optimization, you can inspect the behavior of your swarm and even look for the best hyper-parameters to control swarm behavior. Moreover, the base classes here can be used to rapidly prototype swarm variants. Check it out!

/r/Python
https://redd.it/7c0ju0
Trying to plot a Fourier transform.

I have to plot y = (4/np.pi) * sum((np.sin(n*x))/(n)) where I sum over x. I have shown attempt below, my problem is that is sums over x and n. I don't know how to fix this.

n = np.linspace(1, 11, 11)
x = np.arange(101)
y = (4/np.pi) * np.sum((np.sin(n*x))/(n))
plt.plot(x,y)

/r/Python
https://redd.it/7c1i52
Python Entry job

HI,
im self learning Python for a bout 8 months now, and i think i am intermediate level, but i have a long and solid background as hardware technician, and help desk. i wanna ask 2 questions, first: considering my experience in hardware and IT in general and my age 41! which road i should choose in python? i mean what is most beneficial field that fits to my own work. second: for some one with my understanding of python, what kind a job i can get as an entry level programming? thanks guys

/r/Python
https://redd.it/7c2fie
Emacs as a Django IDE. What's the best way to do this these days?

**tl;dr: There hasn't been a discussion about this on this sub in over a year and I'm curious what tools there are available to configure Emacs as an effective "cloud-based" (over SSH) IDE for Django.**

I've been going through various text editors and IDEs and while I've found some I like, I'd really like to centrally host it myself instead of having synced environments between multiple machines and operating systems. Enter cloud-based IDEs. I want to self-host it so that immediately rules out the bulk of the options out there. The self-hosted options I've found haven't been terribly impressive. Then I remembered since I never bothered to learn Emacs or Vim, I had no idea what people who insisted on using them as IDEs were on about. After some research, I decided to try Emacs first.

So my first trial is going to be Emacs hosted in an LXD container that I just SSH into for development. While I'm not comfortable navigating it without a cheatsheet yet I very much like the layout and working in the terminal. My question is how best to configure it for modern versions of Django and Python development?

I found [this page on the wiki](https://code.djangoproject.com/wiki/Emacs) but it appears to be a bit outdated so I'd like to know if there are any other options I should try (and possibly add to the wiki). The first tool, python-django.el hasn't been updated in over two years and the intro link is dead. Pony Mode looks actively maintained and I intend to try it. New django-mode claims to be the newest and best but there's zero documentation and it doesn't look very actively maintained.

Anything else I should be looking into?

/r/django
https://redd.it/7c2pza
[AF] Explanation of `pip install --editable .`

The current [Flask documentation shows](http://flask.pocoo.org/docs/0.12/tutorial/packaging/) that flask apps should be created as a package. That includes a `setup.py` and `MANIFEST.in`.

If I'm not distributing my app for someone else to use, why would I do this?

If I didn't want to go through this setup, how would I configure my app so I could follow the example? e.g.


export FLASK_APP=flaskr
export FLASK_DEBUG=true
flask run


/r/flask
https://redd.it/7bz93o