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
JQuery/Ajax to call a server side function?

I am having some difficulty with the syntax to actually call a python(server side) function from a button on my html page.

I have an html table with a button on each row. I understand the concept of making a call back to the python application to run

def somefunction(someVarFromTable):

Which is located on my app.py file for now.

But the syntax of JS is throwing me off. Any resource recommendations? Thanks

EDIT:
Apprently I did NOT have a firm grasp of the concept. I was able to meet my needs by calling a {{ url_for(somefunction), someVarFromTable }} on button click and then redirecting back to my updated table.

/r/flask
https://redd.it/7bkmrr
When you confess something to your girlfriend & she keeps bringing it up

TypeError: input expected at most 1 arguments, got 4

/r/Python
https://redd.it/7bptca
Advice to beginners - avoid generic class-based views when you are starting

When I started learning Django, I followed the Django and Mozilla tutorials. Both those tutorials recommended using generic class-based views.

Now it is cool that generic class-based views will save you coding time, but as a Django beginner, when you have very little knowledge of how views work at all, using generic class-based views will only serve to confuse you further.

For Django beginners I'd recommend to write only function-based views or your own class-based views, because they force you to write all the code yourself which will help you understand Django's MVT system much better.

The time you save in the beginning with generic class-based views will only confuse you and actually waste more time later on when you need to add much more detailed processing into your views.

My opinion only; I've been coding full time with Django for about 1.5 months.

/r/django
https://redd.it/7bnvmu
I just finished up making a short series on the basics of NumPy and thought I would share it

https://www.youtube.com/watch?v=FxMS9I49HL8&list=PLmp4AHm0u1g3KQWb_z0b4CzSkyZpIqpe5

Hi everyone, I just finished putting together a quick tutorial series which will guide you along the basics of NumPy. I cover things like, creating an array from scratch, reading an array from a csv file, understanding array dimensions and indexing as well as many basic operations like addition, matrix multiplication and summing. If you follow the series to the end you should have the foundation to start learning to use NumPy for machine learning/ deep learning operations in under an hour.

/r/Python
https://redd.it/7bpzop
Writing a basic x86-64 JIT compiler from scratch in stock Python
https://csl.name/post/python-jit/

/r/Python
https://redd.it/7btwa9
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