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
How to work with Django in Windows 10?

Hi. In all my Django programming life I have been developing in Ubuntu Linux. I still use Ubuntu at home. It's awesome. Now I got a new job and I have to work on Windows (10). I have successfully installed WSL and bash terminal which I use for ssh connections and other things. So, now what? Should I keep using bash terminal in windows 10 for all my developing purposes? (Python, Django, vim, PostgreSQL, virtualenvrapper, etc) or should I go full-on-windows and install PyCharm (which is my main working IDE), Windows-PostgreSQL, windows-python, virtulanevwrapper-win, etc and use bash-terminal only for ssh?

/r/django
https://redd.it/7c6zk8
Tiket untuk peserta PyCon pertama di Indonesia telah tersedia. Grab it fast before you missed it, guys!

https://goo.gl/xDLgan
use python pandas to show csv to placeholder in web file

I have a csv file and need to convert it to view it in html. I know python pandas can do it with

df = pd.read_csv("myfile.csv")
df.to_html('output.html')'

but I don't want to show it in single web page, I have index.html file and I want to show it in there but in another section.

/r/Python
https://redd.it/7c6s75
Please help to improve the awesome-jupyter list on github!

You can *fork* and pull-request the [github](https://github.com/postpdm/awesome-jupyter) repo, or place the [issue](https://github.com/postpdm/awesome-jupyter/issues) to github repo, or post the interesting links here.

Thank you!

/r/IPython
https://redd.it/7c7ur6
Advice for starting a Flask application

I'm going to create a flask-rest api for my iOS app. When I'm developing the API should I deploy on heroku and every time I make a change commit the code and test it, or should I run everything locally then deploy when I'm finished with the API? I just feel I should test it on production servers then just on my computer locally.

/r/flask
https://redd.it/7bxuvg
Apache with wSGI Configuration

I have installed Apache2.4.18 on my Ubuntu machine. I can access the 'Apache2 Ubuntu Default Page' from outside my home network, so Apache seems to be working.

I have a working Django website that I can access at my localhost (127.0.0.1:8000).

I need to configure Apache to serve my Django website instead of its Default page.

[Django's guide](https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/modwsgi/) says to edit Apache's 'httpd.conf' file, but no such file exists on my machine.

[This guide](https://www.thecodeship.com/deployment/deploy-django-apache-virtualenv-and-mod_wsgi/) walks me through the creation of a file that looks similar to what the Django guide is talking about, but there seems to be some major differences between the two.

I don't know where the 'httpd.conf' file should be located. I'm not sure whether the filename needs to be 'httpd.conf' or not. I don't know what information should be contained within 'httpd.conf'.

Thanks for any help in advance!

/r/djangolearning
https://redd.it/7c9ams
To use Turbolinks 5 with Django, how can I automate inclusion of the Turbolinks-Location header when using redirect()?

According to the Turbolinks 5 documentation for "Following Redirects" (https://github.com/turbolinks/turbolinks#following-redirects):

> When you visit location `/one` and the server redirects you to location
> `/two`, you expect the browser’s address bar to display the redirected
> URL.
>
> However, Turbolinks makes requests using `XMLHttpRequest`, which
> transparently follows redirects. There’s no way for Turbolinks to tell
> whether a request resulted in a redirect without additional
> cooperation from the server.

And the solution for this is to:

> send the `Turbolinks-Location` header in response to a visit that was
> redirected, and Turbolinks will replace the browser’s topmost history
> entry with the value you provide.

>The Turbolinks Rails engine performs this optimization automatically for non-GET XHR requests that redirect with the `redirect_to` helper.

I have a great interest in using Turbolinks on my Django (1.11) project and I'm wondering if anyone could point me in the right direction of how to create a new Django redirect() function or modify the existing one to always include the Turbolinks-Location header that is needed for redirects to function as expected. I definitely do not want to be manually setting this header every time I do a redirect.

There is a similar entry in the 'Redirecting After a Form Submission' section (https://github.com/turbolinks/turbolinks#redirecting-after-a-form-submission) I would also appreciate any help in understanding how to implement:

> If form submission results in a state change on the server that
> affects cached pages, consider clearing Turbolinks’ cache with
> `Turbolinks.clearCache()`.
>
> The Turbolinks Rails engine performs this optimization automatically
> for non-GET XHR requests that redirect with the `redirect_to` helper.

I did see there is a "Drop-in turbolinks implementation for Django" package on github but this is forked from turbolinks-classic and sourcecode has no mentions of the Turbolinks-Location header so I am sure this is not what I'm looking for.

/r/django
https://redd.it/7c9wh4
A drop-in Erlang node implementation in Python, designed to allow access to existing Python projects from Erlang and the opposite. With just a few lines of startup code your Python program becomes a fully functional Erlang node.
https://github.com/esl/Pyrlang

/r/Python
https://redd.it/7cb2to
Python Library for implementing Publish Subscribe model on Raspberry Pi

Hey, guys. Which python library, do you think is best for implementing a Publish-Subscribe architecture.

More specifically, i want to implement such an architecture for passing information between various sensors and actuators in an asynchronous way on a Raspberry Pi, instead of using the traditional infinite main loop approach.

Kindly advise

/r/Python
https://redd.it/7c8x8d
Revamping design decisions - worth doing now?

So it's been about 1.5 months since I started building a project with Django. Looking at a lot of my old code, unsurprisingly I did not follow best practices. This is especially true with the names of views and models - instead of having a simple model name like **Subscriber**, I'd have something like **UserPremiumSubscription**. There are also major design decisions that I made which were bad, like creating 2 models when I should have just made 1.

I suppose my question applies to not just using Django, but all programming in general - Is it worth going back and changing all the minor nuances to follow best practices? Or should I just keep going and follow best practices for all the code in the future, and go back and do a final fix right before launching the project for production?

It would make sense to go back and fix things now, but what I am worried about is having to go back a 2nd or 3rd time in the future after I become more experienced with Django.

/r/django
https://redd.it/7cck3k
Flask-Security?

I am looking at Flask-Security documentation and noticed there is a basic configuration and one with session configuration.

Which one should I use? Is the setting with session worth the extra effort?

/r/flask
https://redd.it/7bw7f1
Parsing 1,000,000 Lines of Shell Scripts in 6,000 lines of Python

I thought some people here may be interested in a fairly elaborate parser written in Python.

[OSH 0.2 - Parsing One Million Lines of Shell](http://www.oilshell.org/blog/2017/11/10.html)

Source code:

https://github.com/oilshell/oil

Most of the parser is in the `osh/` directory, and the rest of the shell is in the `core/` directory.

I may be moving away from Python in the near future for speed/size reasons [1], but right now the parser is 100% Python.

There is a good amount of detail on the parser in the blog [2]

[1] http://www.oilshell.org/blog/tags.html?tag=OVM#OVM

[2] http://www.oilshell.org/blog/tags.html?tag=parsing-shell#parsing-shell



/r/Python
https://redd.it/7ccunw
Career Advice for an I.T. Field Consultant learning Python

I'm an I.T. field consultant based in NYC working for a MSP and learning Python to expand my skills and market myself for a new job in about a year. I don't have a degree but have managed to come a long way with my knowledge of networking, Linux, macOS, and Windows. I'm extremely calm and empathetic which is also one of my greatest professional skills along with my ability to solve computer problems. I'm learning Python3 and Django currently and I was just curious what job positions I should be looking at to market myself based on my current skill set.

Thanks so much.

/r/Python
https://redd.it/7ccjgk
Using a form to delete an object

I'm trying to delete an object using a form and DeleteView. What I have right now is giving me an error `Reverse for 'deleteblock' with arguments '('',)' not found. 1 pattern(s) tried: ['classroom/(?P<pk>[0-9]+)/deleteblock/$']` I get this error as soon as I load the template adjust.html.

models.py


class Classroom(models.Model):
BLOCK_NUMBER = (
('11', 'Block 1-1'),
('12', 'Block 1-2'),
('13', 'Block 1-3'),
('14', 'Block 1-4'),
('21', 'Block 2-1'),
('22', 'Block 2-2'),
('23', 'Block 2-3'),
('24', 'Block 2-4'),
)
class_list = models.TextField()
course_block = models.CharField(max_length=10, choices=BLOCK_NUMBER)

class DeleteForm(ModelForm):
class Meta:
model = Classroom
fields = ['course_block']

views.py


def adjust(request):
classroom = Classroom.objects.all()
if request.method == 'POST':
form = DeleteForm(request.POST)
if form.is_valid():
return render(request, 'classroom/adjust.html', {'form':form,'classroom':classroom})
else:
form = DeleteForm()

return render(request, 'classroom/adjust.html', {'form': form,'classroom': classroom})

class BlockDeleteView(DeleteView):
model = Classroom
slug_field = 'id'
success_url = reverse_lazy('classroom:classroom')

delete_block_view = BlockDeleteView.as_view()

urls.py


urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^classup/$', create_classroom_view, name='classroom'),
url(r'^(?P<pk>[0-9]+)/deleteblock/$', delete_block_view, name='deleteblock'),
url(r'^adjust/$', views.adjust, name='adjust'),
url(r'^random/$', views.block, name='random'),

template - adjust.html


<form action="{% url 'classroom:deleteblock' classroom.id %}" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="submit" />
</form>


What I think should happen is the following. /adjust/ points to the adjust view. This view gets all of the Classroom objects and prepares DeleteView form. The modelform creats a choice list with course_block. I get a form with a list and I choose the course_block that I want to delete. When I click on the submit button, the chosen object's classroom.id matches a deleteblock url, which corresponds to the DeleteView for that object. The successful url from the DeleteView goes back to the classroom view.

For testing purposes, in the adjust view if I change the query to `classroom = Classroom.objects.all().first()`, I don't get an error and the form and form submission behave as expected - other than the fact that the form doesn't really do anything because it is classrooom.objects.all().first() that gets deleted.

I've read the documention on the djangoproject but I'm definitely missing something here.

/r/django
https://redd.it/7ce05n