cachelper - A lightweight library of cache helpers
https://github.com/suzaku/cachelper
/r/Python
https://redd.it/6wbynt
https://github.com/suzaku/cachelper
/r/Python
https://redd.it/6wbynt
GitHub
suzaku/cachelper
Contribute to cachelper development by creating an account on GitHub.
Is templating on <script></script> an acceptable practice in the Django community?
I haven't worked enough with a Django project built by someone else so I can't tell.
There are situations where it is mandatory that javascript must handle information from the server, but in my opinion, performing an AJAX to retrieve this information is too expensive when one could simply put this information in a template.
For instance, when I needed user information to be passed to JS, I did this:
<script>
{% if request.user.is_authenticated %}
const user = {
name: "{{ request.user.first_name }} {{ request.user.last_name }}",
id: {{ request.user.id }}
};
const csrf = "{{ csrf_token }}";
{% else %}
const user = null;
{% endif %}
</script>
The solution works, and I got what I wanted, but it felt too hacky. Is this an acceptable practice or must I look for a better solution? Is this a common thing in Django projects?
/r/django
https://redd.it/6wbki2
I haven't worked enough with a Django project built by someone else so I can't tell.
There are situations where it is mandatory that javascript must handle information from the server, but in my opinion, performing an AJAX to retrieve this information is too expensive when one could simply put this information in a template.
For instance, when I needed user information to be passed to JS, I did this:
<script>
{% if request.user.is_authenticated %}
const user = {
name: "{{ request.user.first_name }} {{ request.user.last_name }}",
id: {{ request.user.id }}
};
const csrf = "{{ csrf_token }}";
{% else %}
const user = null;
{% endif %}
</script>
The solution works, and I got what I wanted, but it felt too hacky. Is this an acceptable practice or must I look for a better solution? Is this a common thing in Django projects?
/r/django
https://redd.it/6wbki2
reddit
Is templating on an acceptable... • r/django
I haven't worked enough with a Django project built by someone else so I can't tell. There are situations where it is mandatory that javascript...
Django lookup in new tab/window
Hi guys,
I've been lurking around for quite some time now. I finally decided that I make django application by myself. I am trying to create music library for saving your fav music. I have a form where you can search (its django-autocomplete-light plugin) for music than add some notes and save it. I have more than 250k songs in my database. Now I need your help with search. How could I implement something like a lookup i.e. in form you click on search button that opens new window or tab, then you search for song and when you click it you it closes that window/tab and inserts in form.
I appreciate any help.
/r/django
https://redd.it/6wbxkv
Hi guys,
I've been lurking around for quite some time now. I finally decided that I make django application by myself. I am trying to create music library for saving your fav music. I have a form where you can search (its django-autocomplete-light plugin) for music than add some notes and save it. I have more than 250k songs in my database. Now I need your help with search. How could I implement something like a lookup i.e. in form you click on search button that opens new window or tab, then you search for song and when you click it you it closes that window/tab and inserts in form.
I appreciate any help.
/r/django
https://redd.it/6wbxkv
reddit
Django lookup in new tab/window • r/django
Hi guys, I've been lurking around for quite some time now. I finally decided that I make django application by myself. I am trying to create...
Renaming Django's Auth User and App
http://evennia.blogspot.se/2017/08/renaming-djangos-auth-user-and-app.html
/r/Python
https://redd.it/6wb5ay
http://evennia.blogspot.se/2017/08/renaming-djangos-auth-user-and-app.html
/r/Python
https://redd.it/6wb5ay
evennia.blogspot.co.uk
Renaming Django's Auth User and App
N ow that Evennia's devel branch (what will become Evennia 0.7) is slowly approaching completion, I thought I'd try to document an aspect...
Proper docs and packages for mongodb on django?
i recently started messing around with django, definitely really interesting but im a big mongodb fan and cant seem to find any recent packages, the last django nonrel that i see is 1.6? hopefully im just in the wrong section but i went to the deprecated page and then traversed to the non deprecated(what i hope is non deprecated) and that uninstalled my django 1.11.4 to 1.6 or something around there(i fixed it back to current, the mongodb site is actually kind of off as well, i understand python mainly does better with relational db). sorry exited the shell forgot exact version. if you happen to know/find UP-TO-DATE packages please post a link, thanks in advance
/r/django
https://redd.it/6wf3iz
i recently started messing around with django, definitely really interesting but im a big mongodb fan and cant seem to find any recent packages, the last django nonrel that i see is 1.6? hopefully im just in the wrong section but i went to the deprecated page and then traversed to the non deprecated(what i hope is non deprecated) and that uninstalled my django 1.11.4 to 1.6 or something around there(i fixed it back to current, the mongodb site is actually kind of off as well, i understand python mainly does better with relational db). sorry exited the shell forgot exact version. if you happen to know/find UP-TO-DATE packages please post a link, thanks in advance
/r/django
https://redd.it/6wf3iz
reddit
Proper docs and packages for mongodb on django? • r/django
i recently started messing around with django, definitely really interesting but im a big mongodb fan and cant seem to find any recent packages,...
GraphQL and Django in 5 minutes
https://joaorafaelm.github.io/blog/graphql-and-django-in-5-minutes
/r/Python
https://redd.it/6wf95q
https://joaorafaelm.github.io/blog/graphql-and-django-in-5-minutes
/r/Python
https://redd.it/6wf95q
Snippets are unofficial and unmaintained.
http://flask.pocoo.org/snippets/
/r/flask
https://redd.it/6wen7j
http://flask.pocoo.org/snippets/
/r/flask
https://redd.it/6wen7j
reddit
Snippets are unofficial and unmaintained. • r/flask
4 points and 3 comments so far on reddit
How do you develop on a remote server?
Hi guys,
i develop primary desktop application, but my next project will be a website for internal use.
My normal workflow is: Write code with PyCharm Community edition on my windows pc, debug and test it locally. After this, deploy it. Because my endtarget are windows clients, this works very well.
Now my next project will be Django on a Linux server with several extensions, who are not a fan of windows. Trust me, tried it, didn't work. So, how do I do this?
Right at the moment I think about using a VM with VMware Player, but I'm afraid about the lagging while writing code all the time on a remote system.
Can anyone recommend a good practice to develop for a remote server?
/r/django
https://redd.it/6wehz1
Hi guys,
i develop primary desktop application, but my next project will be a website for internal use.
My normal workflow is: Write code with PyCharm Community edition on my windows pc, debug and test it locally. After this, deploy it. Because my endtarget are windows clients, this works very well.
Now my next project will be Django on a Linux server with several extensions, who are not a fan of windows. Trust me, tried it, didn't work. So, how do I do this?
Right at the moment I think about using a VM with VMware Player, but I'm afraid about the lagging while writing code all the time on a remote system.
Can anyone recommend a good practice to develop for a remote server?
/r/django
https://redd.it/6wehz1
reddit
How do you develop on a remote server? • r/django
Hi guys, i develop primary desktop application, but my next project will be a website for internal use. My normal workflow is: Write code with...
Quick script to delete your reddit comments
I noticed the tampermonkey script just edits your comments, not deleting them, so I wrote the following script to do both. You'll need to register the app on your account and put in client id/secret
import praw
reddit = praw.Reddit(client_id='',
client_secret='',
password='',
user_agent='deletes my comments',
username='')
redditor = reddit.redditor("")
for comment in redditor.comments.new():
comment.edit(".")
comment.delete()
It deletes your comments most recent to oldest.
Pro tip: make a shell script that includes this code just by adding a shebang followed by a path to your interpreter and run it from there. Also make an alias, helps when you need to find/run this script quickly.
/r/Python
https://redd.it/6wfqsv
I noticed the tampermonkey script just edits your comments, not deleting them, so I wrote the following script to do both. You'll need to register the app on your account and put in client id/secret
import praw
reddit = praw.Reddit(client_id='',
client_secret='',
password='',
user_agent='deletes my comments',
username='')
redditor = reddit.redditor("")
for comment in redditor.comments.new():
comment.edit(".")
comment.delete()
It deletes your comments most recent to oldest.
Pro tip: make a shell script that includes this code just by adding a shebang followed by a path to your interpreter and run it from there. Also make an alias, helps when you need to find/run this script quickly.
/r/Python
https://redd.it/6wfqsv
reddit
Quick script to delete your reddit comments • r/Python
I noticed the tampermonkey script just edits your comments, not deleting them, so I wrote the following script to do both. You'll need to register...
[D] would anyone be interested in a machine-learning focused linux distro?
I was thinking about how hard it is to set everything up (CUDA, installing different frameworks, etc) once you put together a new machine...
Would there be any interest in a linux distribution (ubuntu variant) that comes pre-installed with stuff like CUDA, tensorflow, torch, a nice IDE, etc, so you can just install the distro and get started with machine learning stuff right away? I could easily throw something like this together and put it on github or something over the coming long weekend...
Let me know if there is interest and things that I should include in it.
**Edit: made an empty git repo; I'll put stuff there this weekend when I have time to work on it... https://github.com/robbiebarrat/MachineLearningLinux**
/r/MachineLearning
https://redd.it/6wfgfz
I was thinking about how hard it is to set everything up (CUDA, installing different frameworks, etc) once you put together a new machine...
Would there be any interest in a linux distribution (ubuntu variant) that comes pre-installed with stuff like CUDA, tensorflow, torch, a nice IDE, etc, so you can just install the distro and get started with machine learning stuff right away? I could easily throw something like this together and put it on github or something over the coming long weekend...
Let me know if there is interest and things that I should include in it.
**Edit: made an empty git repo; I'll put stuff there this weekend when I have time to work on it... https://github.com/robbiebarrat/MachineLearningLinux**
/r/MachineLearning
https://redd.it/6wfgfz
Update / Save model date value directly from template?
Hello all,
I am still quite inexperienced in Django and I was wondering if it would be at all possible to update/save today's date in my database directly from the template?
I have a Django-filter filterView (listView) that shows the list of people that are in my department which I currently have in my database. And I would like to update a datetime value (when the people have last been visited) to today's date by clicking on a <a><\a> link that shows in the list. That way I don't have to setup an update view just to update when I've last visited the coworkers. Is something like this even possible?
I did try to implement a function in my models.py with the @property tag but when I refresh the webpage, or visit the page it automatically updates it without having to click on the link.
Edit: Here is the code:
# models.py
@property
def update_visit_date(self):
self.last_visit = timezone.make_aware(datetime.datetime.today())
super(Directory, self).save()
return reverse('directory_list')
# snippet from my template directory_list.html
{% for contact in items %}
<tr>
<td>{{ contact.first_name }}</td>
<td>{{ contact.last_name }}</td>
<th><a href="{{ contact.get_absolute_url }}">{{ contact.email_address }}</a></th>
<td>{{ contact.phone_number_1 }}</td>
<td>{{ contact.get_department_display }}</td>
<td>{{ contact.room_number }}</td>
{% if contact.is_past_due == 'no_visit_performed' %}
<td class="info">{{ contact.last_visit }}<a href="{{ contact.update_visit_date }}"> {% bootstrap_icon "plus-sign" %}</a></td>
{% elif contact.is_past_due == 'visit_good' %}
<td class="success">{{ contact.last_visit }}<a href="{{ contact.update_visit_date }}"> {% bootstrap_icon "plus-sign" %}</a></td>
{% elif contact.is_past_due == 'visit_old' %}
<td class="warning">{{ contact.last_visit }}<a href="{{ contact.update_visit_date }}"> {% bootstrap_icon "plus-sign" %}</a></td>
{% elif contact.is_past_due == 'need_visit' %}
<td class="danger">{{ contact.last_visit }}<a href="{{ contact.update_visit_date }}"> {% bootstrap_icon "plus-sign" %}</a></td>
{% endif %}
</tr>
{% empty %}
Is this something that is possible, the performing a CRUD from a template link? Or am I going about this the wrong way? Any help is greatly appreciated. Thank you very much!
/r/djangolearning
https://redd.it/6wd8ue
Hello all,
I am still quite inexperienced in Django and I was wondering if it would be at all possible to update/save today's date in my database directly from the template?
I have a Django-filter filterView (listView) that shows the list of people that are in my department which I currently have in my database. And I would like to update a datetime value (when the people have last been visited) to today's date by clicking on a <a><\a> link that shows in the list. That way I don't have to setup an update view just to update when I've last visited the coworkers. Is something like this even possible?
I did try to implement a function in my models.py with the @property tag but when I refresh the webpage, or visit the page it automatically updates it without having to click on the link.
Edit: Here is the code:
# models.py
@property
def update_visit_date(self):
self.last_visit = timezone.make_aware(datetime.datetime.today())
super(Directory, self).save()
return reverse('directory_list')
# snippet from my template directory_list.html
{% for contact in items %}
<tr>
<td>{{ contact.first_name }}</td>
<td>{{ contact.last_name }}</td>
<th><a href="{{ contact.get_absolute_url }}">{{ contact.email_address }}</a></th>
<td>{{ contact.phone_number_1 }}</td>
<td>{{ contact.get_department_display }}</td>
<td>{{ contact.room_number }}</td>
{% if contact.is_past_due == 'no_visit_performed' %}
<td class="info">{{ contact.last_visit }}<a href="{{ contact.update_visit_date }}"> {% bootstrap_icon "plus-sign" %}</a></td>
{% elif contact.is_past_due == 'visit_good' %}
<td class="success">{{ contact.last_visit }}<a href="{{ contact.update_visit_date }}"> {% bootstrap_icon "plus-sign" %}</a></td>
{% elif contact.is_past_due == 'visit_old' %}
<td class="warning">{{ contact.last_visit }}<a href="{{ contact.update_visit_date }}"> {% bootstrap_icon "plus-sign" %}</a></td>
{% elif contact.is_past_due == 'need_visit' %}
<td class="danger">{{ contact.last_visit }}<a href="{{ contact.update_visit_date }}"> {% bootstrap_icon "plus-sign" %}</a></td>
{% endif %}
</tr>
{% empty %}
Is this something that is possible, the performing a CRUD from a template link? Or am I going about this the wrong way? Any help is greatly appreciated. Thank you very much!
/r/djangolearning
https://redd.it/6wd8ue
reddit
Update / Save model date value directly from... • r/djangolearning
Hello all, I am still quite inexperienced in Django and I was wondering if it would be at all possible to update/save today's date in my database...
[P] Pytorch-c++: use your pytorch trained models in c++
https://github.com/warmspringwinds/pytorch-cpp
/r/MachineLearning
https://redd.it/6wgwxb
https://github.com/warmspringwinds/pytorch-cpp
/r/MachineLearning
https://redd.it/6wgwxb
GitHub
GitHub - warmspringwinds/pytorch-cpp: Pytorch C++ Library
Pytorch C++ Library. Contribute to warmspringwinds/pytorch-cpp development by creating an account on GitHub.
Microservices with Docker, Flask, and React - Part 5 (Docker Hub, AWS ECS and RDS)
http://testdriven.io/part-five-intro
/r/flask
https://redd.it/6wjf0p
http://testdriven.io/part-five-intro
/r/flask
https://redd.it/6wjf0p
reddit
Microservices with Docker, Flask, and React - Part 5... • r/flask
2 points and 0 comments so far on reddit
Sound Pattern Recognition with Python
https://medium.com/@almeidneto/sound-pattern-recognition-with-python-9aff69edce5d
/r/Python
https://redd.it/6wiywl
https://medium.com/@almeidneto/sound-pattern-recognition-with-python-9aff69edce5d
/r/Python
https://redd.it/6wiywl
Medium
Sound Pattern Recognition with Python
As you can probably tell from the title in this post I will be toying around with python and sound to detect sound patterns. More…
Is there any tutorial on how to run pyaudio with flask?
I'm basically trying to record audio through a clients web browser from a remote server. I was hoping to use this python script (which imports pyaudio) below to record.
import pyaudio
import wave
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
CHUNK = 1024
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "file.wav"
audio = pyaudio.PyAudio()
# start Recording
stream = audio.open(format=FORMAT, channels=CHANNELS,
rate=RATE, input=True,
frames_per_buffer=CHUNK)
print ("recording...")
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
print ("finished recording")
# stop Recording
stream.stop_stream()
stream.close()
audio.terminate()
waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
waveFile.setnchannels(CHANNELS)
waveFile.setsampwidth(audio.get_sample_size(FORMAT))
waveFile.setframerate(RATE)
waveFile.writeframes(b''.join(frames))
waveFile.close()
However i am not sure what to do about the frontend. Is it a simple html form with a post request? I know that it wouldnt make any sense if that were solely the case. If anyone has gone through something similar as this, can you pinpoint me to some tutorials or documents available on how i can connect the python script to a web browser via flask?
Thanks
/r/flask
https://redd.it/6wg24z
I'm basically trying to record audio through a clients web browser from a remote server. I was hoping to use this python script (which imports pyaudio) below to record.
import pyaudio
import wave
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
CHUNK = 1024
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "file.wav"
audio = pyaudio.PyAudio()
# start Recording
stream = audio.open(format=FORMAT, channels=CHANNELS,
rate=RATE, input=True,
frames_per_buffer=CHUNK)
print ("recording...")
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
print ("finished recording")
# stop Recording
stream.stop_stream()
stream.close()
audio.terminate()
waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
waveFile.setnchannels(CHANNELS)
waveFile.setsampwidth(audio.get_sample_size(FORMAT))
waveFile.setframerate(RATE)
waveFile.writeframes(b''.join(frames))
waveFile.close()
However i am not sure what to do about the frontend. Is it a simple html form with a post request? I know that it wouldnt make any sense if that were solely the case. If anyone has gone through something similar as this, can you pinpoint me to some tutorials or documents available on how i can connect the python script to a web browser via flask?
Thanks
/r/flask
https://redd.it/6wg24z
reddit
Is there any tutorial on how to run pyaudio with flask? • r/flask
I'm basically trying to record audio through a clients web browser from a remote server. I was hoping to use this python script (which imports...
Jupyter notebook code cell empty lines / scrolling
Since today, all my jupyter code cells have some empty lines at the end of a code block which are not real lines that I can delete, but rather is just empty space. In theory, this does not bother me, but unfortunately, each cell thus has scrolling available, and I inevitable scroll all the time in a cell which is quite annoying. It seems to only happen in Chrome though.
Anyone got an idea how to tackle this? Thanks.
/r/IPython
https://redd.it/6wjm2z
Since today, all my jupyter code cells have some empty lines at the end of a code block which are not real lines that I can delete, but rather is just empty space. In theory, this does not bother me, but unfortunately, each cell thus has scrolling available, and I inevitable scroll all the time in a cell which is quite annoying. It seems to only happen in Chrome though.
Anyone got an idea how to tackle this? Thanks.
/r/IPython
https://redd.it/6wjm2z
reddit
Jupyter notebook code cell empty lines / scrolling • r/IPython
Since today, all my jupyter code cells have some empty lines at the end of a code block which are not real lines that I can delete, but rather is...
A Human's Guide to setup.py (by Kenneth Reitz)
https://github.com/kennethreitz/setup.py
/r/Python
https://redd.it/6wkk9p
https://github.com/kennethreitz/setup.py
/r/Python
https://redd.it/6wkk9p
GitHub
GitHub - kennethreitz/setup.py: 📦 A Human's Ultimate Guide to setup.py.
📦 A Human's Ultimate Guide to setup.py. Contribute to kennethreitz/setup.py development by creating an account on GitHub.
share your jwt/swagger implementation?
I'm having a hard time with this.
Here's what I have so far. The docs work, but the problem is it's not giving me the ability to enter a token on the "try me out!" examples. Also, when passing the token it's expecting `Authorization: JWT <token>` but per setup it's receiving `Authorization: <token>`. I don't want to remove the `JWT` prefix.
settings.py
...
JWT_AUTH = {
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=300),
'JWT_ALLOW_REFRESH': True,
'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
'JWT_AUTH_HEADER_PREFIX': 'JWT',
'JWT_AUTH_COOKIE': None,
}
SWAGGER_SETTINGS = {
'SECURITY_DEFINITIONS': {
'jwt': {
'type': 'apiKey',
'description': 'jwt Token',
'name': 'Authorization',
'in': 'header'
}
},
'USE_SESSION_AUTH': False,
'SHOW_REQUEST_HEADERS': True,
'JSON_EDITOR': True,
}
...
urls.py
...
schema_view = get_schema_view(title='My API', renderer_classes=[OpenAPIRenderer, SwaggerUIRenderer])
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^api/v1/', include(router.urls)),
url(r'^api/v1/docs', schema_view, name='docs'),
url(r'^rest-api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^api/v1/auth/obtain/', obtain_jwt_token),
url(r'^api/v1/auth/refresh/', refresh_jwt_token),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
...
/r/django
https://redd.it/6wnsjs
I'm having a hard time with this.
Here's what I have so far. The docs work, but the problem is it's not giving me the ability to enter a token on the "try me out!" examples. Also, when passing the token it's expecting `Authorization: JWT <token>` but per setup it's receiving `Authorization: <token>`. I don't want to remove the `JWT` prefix.
settings.py
...
JWT_AUTH = {
'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=300),
'JWT_ALLOW_REFRESH': True,
'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
'JWT_AUTH_HEADER_PREFIX': 'JWT',
'JWT_AUTH_COOKIE': None,
}
SWAGGER_SETTINGS = {
'SECURITY_DEFINITIONS': {
'jwt': {
'type': 'apiKey',
'description': 'jwt Token',
'name': 'Authorization',
'in': 'header'
}
},
'USE_SESSION_AUTH': False,
'SHOW_REQUEST_HEADERS': True,
'JSON_EDITOR': True,
}
...
urls.py
...
schema_view = get_schema_view(title='My API', renderer_classes=[OpenAPIRenderer, SwaggerUIRenderer])
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^api/v1/', include(router.urls)),
url(r'^api/v1/docs', schema_view, name='docs'),
url(r'^rest-api-auth/', include('rest_framework.urls', namespace='rest_framework')),
url(r'^api/v1/auth/obtain/', obtain_jwt_token),
url(r'^api/v1/auth/refresh/', refresh_jwt_token),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
...
/r/django
https://redd.it/6wnsjs
reddit
share your jwt/swagger implementation? • r/django
I'm having a hard time with this. Here's what I have so far. The docs work, but the problem is it's not giving me the ability to enter a token...
Is there a way to make shell context in Django like in Flask?
What I mean is whenever I use python manage.py shell I don't want to keep typing the imports I need from my models, such as from models import User. In Flask, there is a way so that whenever you call python manage.py shell User is already a variable in the shell that you can reference without importing. Can you do a similar thing in Django?
/r/django
https://redd.it/6woap1
What I mean is whenever I use python manage.py shell I don't want to keep typing the imports I need from my models, such as from models import User. In Flask, there is a way so that whenever you call python manage.py shell User is already a variable in the shell that you can reference without importing. Can you do a similar thing in Django?
/r/django
https://redd.it/6woap1
reddit
Is there a way to make shell context in Django like in... • r/django
What I mean is whenever I use python manage.py shell I don't want to keep typing the imports I need from my models, such as from models import...