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
Refresh on Django... book recommendations?

So, over the last two years, I became an intermediate Django developer. I felt like I could read and do almost anything in Django, but was way behind on the "right way" to do things. I changed jobs and spent a year away from programming and I feel like my skills are rusty.

I'd like to do a refresh on Django and I'd like to read a different book than I've read before. I've already read Two Scoops of Django and spent a lot of time in Django documentation.

Any recommendations?

/r/django
https://redd.it/7baea5
Advice for zero downtime deployments with Django

Hello!

I'm starting a new project where high availability is a priority (meaning no dropped HTTP requests). I was wondering what strategies would you recommend for zero downtime deployments?

I realize that complicated DB migrations would have to done in several steps (like removing a column).

Thank you for your advice.

/r/django
https://redd.it/7bc1tk
Question about building an interactive website with Flask

I'm working on a project with the end goal of providing an interactive dashboard of statistical data from a PostgreSQL database.

* I have the Python scripts working to collect, parse and load the data into the database.
* I have the PostgreSQL code working to take the raw data and create the needed materialized views to present nice "tables" that have all the joins and such already done and the indexes needed for performance.
* I have a Flask+Flask-SQLAlchemy application setup that with the main layout, basic flat pages, and a first draft of the dashboard page that display a nicely formatted table of data from a predefined query hard-coded into the view to initialize the page with the most commonly requested data from the database.

But now I'm confused on how to make the website interactive to allow the user to, for example, select from icons in the sidebar to update the table of data based on what they want to see from the database.

I'd appreciate some pointers on different ways to provide this interactivity.

Searching Google isn't helping much because I don't know what to search for in the first place. All I'm finding is how to use Flask as a REST API with SPA frameworks like Angular/React doing all the front-end - not Flask specific solutions.

Edit: As a clarification - by interactivity I mean making choices that would set the parameters to use in the query of the data. The data is historical and read-only, so there won't be any user input forms.



/r/flask
https://redd.it/7b8y4n
[Help] Python KNN weighting during .predict()?

I'm using a KNN algorithm for a class (instructed to use this algorithm, may not what you'd expect for application, see below)

Essentially, we have a raspberry pi set up to collect the signal strengths of 6 local WIFI router Mac addresses. At different locations on a floor of our building we've recorded these signal strengths in .csv files.

Using python I've created a script which uses the functions on [this page](http://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html).

I fit a knn as below:

from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier(n_neighbors=1, algorithm = 'auto')
knn.fit(strengths, labels)

where strengths is a nested array like this:

[[Loc1strengths],[Loc2strengths],[Loc3strengths],[Loc4strengths],[Loc5strengths],[Loc6strengths]]

labels is set up like this:

[Loc1, Loc2, Loc3, Loc4, Loc5, Loc6]



Later in the script, I collect the signal strengths of the 6 local WIFI router Mac addresses and try to predict the location of my pi using knn.predict() and hope to get the location of the pi, Location1 for example.

The results aren't great, it does a relatively poor job of figuring out where it is.

I was wondering if there was a way to weight the function of knn.predict() so that the neighbors of the most recent location are weighted more heavily, the pi won't move to the other side of the floor without crossing the other points.

Any help would be appreciated!


/r/pystats
https://redd.it/7baulc
How can I use a rich text editor in a django blog admin?

I am creating a dynamic blog using Django. I would like to enable the user of this blog to format the blog posts very easily using a rich text editor. How can I implement it with this Django blog admin?

/r/djangolearning
https://redd.it/7b6p83
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/7bddxy
How does a beginner learn Machine Learning?

I usually use R for my work and have a tiny bit of experience with Python. What's the best way for me to go about getting Python under my belt with the goal of mastering basic concepts in machine learning?
Specifically, I'm asking for suggestions in online courses, but also how should I think about this? Any advice is welcome. Thanks!

/r/Python
https://redd.it/7bextj
Trying to get a template/link working in Mezzanine

Hey all,

I'm working on a Mezzanine project. I made a `ProjectLinkPage` class that inherits from Mezzanine's Displayable class. I logged into the Admin section and added a `ProjectLinkPage` object with the slug "some-content." I want to open the template `some-content.html` by going to "http://127.0.0.1:8000/projects/some-content." This does not work. I get a 404 error.

Here's how my directory looks.

myProject/
- myProject/
-- urls.py
- theme/
-- models.py
-- views.py
-- templates/
--- pages/
---- project_pages/
----- project_base.html
----- projects/
------ some-content.html

My `models.py` looks like this:

class ProjectLinkPage(Displayable)
# Fields and `class Meta`, etc...
@models.permalink
def get_absolute_url(self):
return ("project_detail", (), {"slug": self.slug})

`views.py`:

def project_detail(request, slug, template="project_pages/project_base.html", extra_context=None):
project = get_object_or_404(Project, slug=slug, status=2)
context = {
"project": project,
"editable_obj": project
}
context.update(extra_context or {})

templates = [u"project_pages/projects/%s.html" % str(slug), template]
return TemplateResponse(request, templates, context)

`urls.py`:

`url("^projects/(?P<slug>.*)%s$" % _slash, project_detail, name="project_detail"),`.

Have I missed something in these files? What must I change for my browser to correctly locate the `some-content.html` template when I go to "http://127.0.0.1:8000/projects/some-content?"


/r/django
https://redd.it/7bfvm3
User Authentication

Hi everyone. I am new to Django, but I have a question about user authentication. I understand that Django has a built-in authentication service, but I would like to implement another user authentication service. Are there any good resources for implementing third-party user authentication services. Also, do you guys have any recommendations?

/r/django
https://redd.it/7bfp4y
No error but css effects not taking place

I am loading two static files into my HTML code, "animate.css" and "home.css".
For some reason the animate.css effects do take place when I go to the page on my localhost, but the home.css effects do not.

I am not getting a specific error message though. My terminal says this: https://imgur.com/a/BPJZ1
I don't see a specific message that it is getting the home.css file, while I do see a specific message that it is getting the animate.css file.

my code looks like this: https://imgur.com/a/QBXVT
does anybody have an idea why the home.css effects aren't taking place when I go to the page linked to the home.html file ?

/r/django
https://redd.it/7bf9ix
Django and angular host

What’s a good host to put these combo?
I currently have django on heroku. Having trouble pushing angular to heroku so looking for alternatives.

/r/django
https://redd.it/7bj578
User Flow of multi tenant app using django tenant schemas

So I am confused how to handle user schema in django tenant schemas, I want user to sign up and then create their tenant, so i put django.contrib.auth in shared_apps, but that gave the users access to other tenants, so can anyone recommend the ideal way to handle this.

/r/djangolearning
https://redd.it/7bj994
Dynamic page - Views/Templates

A view:

> def index(request):

> url = request.get_full_path()

> url = url.split('/')

>

> ''' url = ['', index , ''] '''

>

> page = 1

>

> '' bla bla ''

>

> if request.full.path[-1] == 'up':

>
> page = page +1

> else == request.full.path[-1] == 'down' and page = page -1.. bla bla

>

>

And the template:

> <a href="whatever/*{{ page }}/up" class='next'> Up </a>

> <a = href="whatever/*{{ page }}/down" class='previous'> Down </a>
>

Now, yeah, it works, until up the point i have to switch the page back or forward, when i get a bug where the last page variable value is rendered before i can get the last section of the buttons's URL's especifying if it's either "down" and page = page -1 or "up" so we go page = page + 1 and to the next page...

What happens then is that the first time i press "Down" after pressing "Up", i still get a positive page count, only from the second time on it works properly in the right direction..

I know it sounds kinda of a no brainer but i'm seriously having trouble thinking of anything quick...

/r/django
https://redd.it/7bcbx7
Trouble with jQuery and flask

Hey guys, not sure if this is the best place for this question. I'm still fairly new at flask and have had a bit of trouble finding what I'm after with a bit of google-fu.

I have a multiple select list on a page within my flask app, using jQuery to dynamically filter the results based on what the user has typed so far [shamelessly pinched from this resource](http://www.lessanvaezi.com/filter-select-list-options/). When I load up the html file on its own, it works fine, but when I actually run the app in flask, it doesn't work! I can only think I've got some of the html in the wrong place, causing flask to not load my jQuery at the right time (or so I've gleaned by my searching). If anyone can help me out, it would be much appreciated. I won't bother pasting my flask code below, its your basic first app type of thing which just uses render_template to load the html.

https://pastebin.com/Dg0q8u14 <link to html


https://pastebin.com/FGeGqm7R <link to jQuery

/r/flask
https://redd.it/7bk33x
Coding text editor for remote server ?

Hi,

I am looking for a text editor to write python code on an amazon server that is not VI/VIM/Nano. I am currently using vim , but I find Komodo much easier to read from. To get to this server I must pass an intermediary server if that makes a diff. I want to be able to edit the scripts I have on the server using a text editor like Komodo Edit or something - without having to upload the changes to the server from my local machine each time.

Hope that makes sense.

Thanks

EDIT:
Didn't realise I could make VIM 'nicer' - Ill just use this : https://realpython.com/blog/python/vim-and-python-a-match-made-in-heaven/#vim-extensions

/r/Python
https://redd.it/7bkb5q