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
Flask GitHub project mainly Java-Script and CSS?

Hi there!

I'm making my first [FlaskApp](https://github.com/SonGokussj4/beta-issues) and it should be mainly `HTML` and `Python` code. But when I added `bootstrap` and because of `modal` manipulations even the `JQuery` and these kind of things, my *Languages bar* looks like:

- JavaScript 69%
- CSS 27%
- HTML 2%
- Python 2%

Is this normal for this kind of application?

Or I shouldn't have those bootstrap/jquery libraries in my repo and instead, have in documentation *"You have to download this and that and put it here and there"*.

(Reasoning: I don't want anyone think I know any JavaScript because I don't... But when they see this, ...)

/r/flask
https://redd.it/6b9pn1
Has Anyone Ever Actually Been Able to Compile PyQt5 to Android with PyQtDeploy?

I love PyQt, I use it almost every day, but for the life of me I can't understand pyqtdeploy, and from reading other testimonies, I'm not the only one.

Has anyone actually been able to make this work? I know getting a language onto a platform it wasn't built for is a pain, but god-damn.

Also, I'm well aware of Kivy, it has very similar pitfalls.


/r/Python
https://redd.it/6b9zua
Where does a generator store it's values?

In [1]: var = ['a', 'b', 'c']

In [2]: gen = (v for v in var)

In [3]: del var

In [4]: gen.next()
Out[4]: 'a'

In [5]: gen.__sizeof__()
Out[5]: 48

In [6]: var = ['a', 'b', 'c', 'd', 'e', 'f']

In [7]: gen = (v for v in var)

In [8]: gen.next()
Out[8]: 'a'

In [9]: del var

In [10]: gen.next()
Out[10]: 'b'

In [11]: gen.__sizeof__()
Out[11]: 48



Where exactly is var stored, and how does the generator find it's values? If it is still in memory, why doesn't the generator's size change?



/r/Python
https://redd.it/6b9mt1
Using DJango purely as a REST aPI provider?

Hello,

I am trying to find resources on building a REST API using Django but so far I have not been able to find resources specifically for that. Would anyone have any recommendations of this topic? Alternatively, if Django is not recommendable for this kind of project, what would you recommend? Not limited to Python.

Thank you!

/r/djangolearning
https://redd.it/6bbudz
iPython flask shell

[iPython flask shell](https://pypi.python.org/pypi/flask-shell-ipython/0.2.2)

This is a flask extensions that doesn't get the credit it deserves. It saved me a couple of times, especially when debugging database connections.

EDIT: added link

/r/flask
https://redd.it/6b9fob
Sending html form data to a python file

**Edit: Figured it out. Check my comment [here](https://www.reddit.com/r/djangolearning/comments/6az249/sending_html_form_data_to_a_python_file/dhkeb8x/)**

Hey! First time visiting the subreddit. Trying to do a little project in Django and have been stuck on something for a while :)

Here's what I'm trying to do:

* Have the user input data on a form
* After clicking submit, the data is able to be loaded into a python file

 

I'm a bit shaky on how to do it. I know it involves some GET/POST method. Code examples below.

**Template**

{% extends "personal/header.html" %}

{% block content %}
{% for user in object_list %}
<h4>User Joined: {{ user.date|date:"Y-m-d" }}
<a href="/pending/{{user.id}}"> {{user.username}}</a> </h4>

<form name="setup" action="." method="POST">{% csrf_token %}
{{form.as_table}}
<input type="hidden" name="username" value={{user.username}}>
<input type="hidden" name="password" value={{user.password}}>
<input type="hidden" name="tags" value={{user.tags}}>
Likes per day: <input type="text" name="likes" value="">
Tags: <input type="text" name="tags" value="tag1,tag2,tag3,etc">
Follows per day:<input type="text" name="follows" value="600">
Proxy <input type="text" name="proxy" value="IP Address">
<input type="submit" value="Start"></form>
{% endfor %}

{% endblock %}

 

From here, I'm not sure:

* What I specify as the action
* How I adjust the urls file
* Do I need to use views?

 

I've done a lot of searching on StackOverflow, Django documentation and Youtube. For some reason, can't seem to wrap my head around what to do next. Also, I'm not worried about sending the password plain text. This isn't anything serious :)



/r/djangolearning
https://redd.it/6az249
Yay!! New Django!

/r/django
https://redd.it/6bgsri
Haystack Rich Content Extraction Example

In the [example](https://django-haystack.readthedocs.io/en/v2.6.0/rich_content_extraction.html) there is a line:

{{ extracted.contents|striptags|safe }}

But in the Django docs, there is a note on the striptags template filter that says
> Note that striptags doesn’t give any guarantee about its output being HTML safe, particularly with non valid HTML input. So NEVER apply the safe filter to a striptags output. If you are looking for something more robust, you can use the bleach Python library, notably its clean method.

How to reconcile this?



/r/djangolearning
https://redd.it/6aw0v3
Optimal project structure when combing Django with front end such as npm and materialize.css?

The Project structure I've got looks now like this:


- /Root
- - /proj_env
- - /main_app
- - /website_app
- - - /templates
- db.sqlite3
- manage.py


I'm not showing every single file here as you see but just a rough example of my project structure. And I'm wondering where to initialize npm and can I just put a **static** directory in the root directory or does it need to be in one of the app directories?


I just know that node modules should at least not be in a static directory.

/r/djangolearning
https://redd.it/6aef6t
Django Developer Panel - Chrome Devtools Extension

Hello /r/django! Today I released a tool I've been working on called Django Developer Panel, which surfaces useful debug information from Django projects to Chrome's developer tools.

[I did a little writeup on our company blog today](http://hirelofty.com/blog/open-source-project-django-developer-panel/) to explain the rationale and lay out a small roadmap for future development, but the gist is it's simple to set up (grab the chrome extension and then add one middleware class to your project settings) and is focused heavily on application state, particularly when using Class Based Views.

**Python source:** https://github.com/loftylabs/django-developer-panel

**Chrome source:** https://github.com/loftylabs/djdevpanel-devtools


**PyPI package:** https://pypi.python.org/pypi/django-developer-panel/0.1.1

**Chrome Extension:** https://chrome.google.com/webstore/detail/django-developer-panel/joeiapdjinonjadfbdabogjimfffpfph?hl=en-US

Looking for contributors and users to test against their applications!


/r/django
https://redd.it/6bhtec
Django project with live updating data

Hello,

This sub has always been very helpful, so I wanted to ask around if anyone has built a project similar to mine and whether they could share some insights:

I have a fully functional django project that has all of the base components, but I would like to merge some of its functionalities with an existing MySQL tick database (adds a row every second for financial data). For instance, the tick database's values would change a client (in the django project db) 's account value and such.

How could I merge the functionality of these two databases (django user db + MySQL tick database) in order to dynamically generate live HTML updates to values which are contingent on both systems, as well as changing some of the existing values in the django user db? What kind of architecture should I aim for? I'm unfortunately very much not sure where to start.

Thanks in advance

/r/django
https://redd.it/6bizbn
How to solve a zero division error in an opencv function in django views?

I'm trying to find the center of contours using an opencv function and then take those points and plot them. My main problem is that the opencv function keeps giving me a zero division error. The code is as follows:


def Contours(request):

filename="C:/Users/ishraq/Downloads/traffic2.mp4"
cv2.ocl.setUseOpenCL(False) #get rid of error:(-215) The data should normally be NULL! in function
NumpyAllocator::allocate
vidcap = cv2.VideoCapture(filename)
fgbg = cv2.createBackgroundSubtractorMOG2()


while(vidcap.isOpened()):
success, frame = vidcap.read()
fgray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
fgmask = fgbg.apply(fgray)
ret,fgmaskthresh = cv2.threshold(fgmask,127,255,0)

_, contours, hierarchy = cv2.findContours(fgmaskthresh.copy(),1,2)

mask = np.zeros(fgray.shape, np.uint8)



count=0;
for contour in contours:

count=count+1

cnt=contours[0]


M=cv2.moments(cnt)


cX = float(M['m10'] / M['m00'])


cY = float(M['m01'] / M['m00'])

cv2.drawContours(mask,contours,-1,(255,100,100),1)

cv2.imshow('frame',fmaskthresh)





if cv2.waitKey(1) & 0xFF == ord('q'):
break

vidcap.release()
cv2.destroyAllWindows()

return render_to_response("app/VideoPlayer.html",{'Cx':cX,'Cy':cY})

I looked at the stack trace and found that the cX and cY values are always 0. I can't figure as to what is going wrong that my code is defaulting the two variables to zero. How do I solve this so that my cX and cY variables don't default to 0?

/r/django
https://redd.it/6bjzx6
Searching a database for what matches most of my searching criteria

I am using Flask-SQLAlchemy and MySQL. But if there is no propper solution for this task using this setup I am still interested in other setup's solutions.

What I want to do is searching the database for multiple criteria and getting a list sorted by what is matching most criteria. For example I look for

color=red
size=large
type=fruit

Then I would get a list beginning with objects that meet all criteria, then objects meeting just 2 criteria,...
An unefficient way to do this would be querying for each criteria on its own and comparing each result. But this would be stupid for larger databases or many filters I think. Is there a more efficient way? Should I prefer having those criteria as database table as well i.e. many-to-many relationships? Or should I create rows for the criteria in the original table?

As I said I would prefer solutions using my setup but if there is no propper way to do it I would have to think about another setup since those kind of searches are essential for my project.

/r/flask
https://redd.it/6bj0yj
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/6bhnzq