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
Help: setup a workflow to create my content with vim

Hello ! I need your advices on a question I am asking myself since few weeks. I want to make my website (blog, comments, portfolio and resources, no CDN) and I was highly hyped for a static site generator.
Why ? Because this could allow me to write my content as files, and then push them on the server very easily. Plus, don't need to go on the admin panel. Problem ? I can't handle dynamic content (just comments for the moment) and I don't want to use a third-party that do it for me.

So I was hopping that someone could help me on this one, is there a way to have a a website using a database, but I push and update my content with files ?

/r/django
https://redd.it/6c2kw0
Do i always need WTF forms?

Question is pretty self-explanatory. Do i always need it? I use ReactJS on the front-end, idk if that means anything at all.

/r/flask
https://redd.it/6bzv4m
Post-Python Dissatisfaction Syndrome

Hello /r/Python,

First of all, this is a serious post and by no means I am trying to be humorous here. I suffer from post-Python dissatisfaction syndrome, that is, any other programming language seems just not as expressive, as powerful, and as beautiful as Python. I abstain from mentioning any names to start a flame war, but with many languages that I considered, popular-and-hype or old-and-traditional, that was how I felt.

I wanted to ask you if that's also the case for you, **and** whether you can give me some suggestions for a different programming language. I'm looking for a preferably (AOT) compiled language, although my chief concern is execution speed and the expressiveness of Python. Also, a mature or at least good enough ecosystem of libraries is equally important (for GUI at least).

I asked here because I wanted to hear Pythonistas' preferences for another Pythonic language, sorry if it's considered out-of-place. Feel free to contribute your own opinion on any other language that you consider to be Pythonic.

Thanks!

/r/Python
https://redd.it/6c1jnv
Metaclasses in Python - one of my first blogposts. I'd like to hear some feedback.
https://millionintegrals.com/post/metaclasses-in-python/

/r/Python
https://redd.it/6c2x5u
cannot get django-select2 working properly

I have a ModelMultipleChoiceField that I want to replace with something from django-select2. It is not working for some reason, and I can't find a good example to copy from, since it's apparently so easy to do!


Model (simplified):

class Ingredient(models.Model):
listed_name = models.CharField(max_length=50, unique=True)
class Combination(models.Model):
ingredients = models.ManyToManyField(Ingredient)


When I try in my fields.py the following:

class CombinationForm(forms.Form):
ingredients = forms.ModelMultipleChoiceField(queryset=Ingredient.objects.all(),
widget=ModelSelect2MultipleWidget(queryset=Ingredient.objects.all(), search_fields=['listed_name__icontains']))

I get an empty widget on my webpage. When I try just setting

widget=Select2MultipleWidget()

I just get the usual Django widget, correctly populated with the Ingredient objects.


I cannot figure out what else I should be trying. I am using a forms.Form rather than a ModelForm because I have a validator, and I am under the impression that including it means that I would have to custom define my Field anyway.

I have jQuery on the page, added django-select2 to my installed apps, and included the urlPattern "url(r'^select2/', include('django_select2.urls'))," into my project's urls.py file just in case.

/r/djangolearning
https://redd.it/6bslnt
Building a surveillance system, some ideas would be a lot of help

I'm building a [surveillance system](https://imgoat.com/uploads/f4922f4556/17373.JPG) for my home, but I don't know where to start.

First off, I'm familiar with Django servers, I'm familiar with automate (android app), I'm half decent at python and I know how to google things. But I'm not sure as of yet what exactly I should be googling.

What I need help with is finding the best way to stream video from my android to my raspberry, and my raspberry over the internet. I'd like to use django, automate and IP Webcam (another android app) because I already know how these work, but If there's an inherent problem with that, or some other route is much easier, I'd just use something different.

Also, what is the safest encryption to use for this kind of thing?

When I'm done, I'll post a report here so the community can learn and emulate, and on that note, I recently built a IOT home automation thing that waters my plants with R.Pi+django for my electronic engineering degree, is there any interest for a translated copy of the report?

/r/django
https://redd.it/6c53ue
can (or should) ipython or Jupyter console be able to edit a class?

Hello. I am using ipython3, and also trying with jupyter console and have not found a way to %edit a class that I enter in.

If I enter in something like:

class Parent(object):
def test(self):
print("testing")

I do not get any errors and can call and use objects of that type. But I am not able to %edit that class. For example, I get:

/usr/local/lib/python3.6/site-packages/IPython/core/magics/code.py:503: UserWarning: The file where `<class '__main__.Parent'>` was defined cannot be read or found.
'cannot be read or found.' % data)


But if I enter a function, like 'def testit():', then I can %edit testit as I would expect.

Is there something I am not entering to distinguish the class I am trying to edit?


Thanks!

/r/IPython
https://redd.it/6c7vhh
Upload and process a remote file called by an API REST call with a Django backend

The application is written in Django. I need to A) upload a file (an Excel spreadsheet) from a remote location (it could be via HTTP or SFTP), headless, i.e. without a form--could it be a call to an external process?, B) triggered by a signal/API call issued by a remote client. The file will then be processed (it could be synchronously or asynchronously) to update a database in the backend (this latter part is already working and is implemented with a file which is read locally). What is the best strategy/architecture, and tools (packages, commands, etc.) to use to solve both points A) and B) above?

/r/django
https://redd.it/6c9za7
Help with differentiating types of users

Hello everyone, I'm a bit confused as to how about I can solve this problem.

I have two types of users: parent and child.

Parent users can CRUD objects, and child users can only view.

What is the best way to create a login system so that creating a user can choose between one of these types and that upon login they are directed the their view of their respective user?


Should I just make a User class with a boolean attribute as Parent=true/false?




/r/flask
https://redd.it/6by6zv
Unique Form Urls to update Model Instances

I have a model with a project number field and notes field. I would like to generate a URL for each project number, and on that page have a form field that would allow me to update that note. Any ideas?

I'm getting a name error in my view that "request" is not defined.

Here's what I have so far...

Model:

class Projectsummary(models.Model):
number = models.CharField(db_column='Number', primary_key=True, max_length=50) # Field name made lowercase.
projectnote = models.TextField(db_column='ProjectNote', blank=True, null=True)
overrunnote = models.TextField(db_column='OverrunNote', blank=True, null=True)

View:

def inputs(requset, number):
formnumber = Projectsummary.objects.get(number=number)
form = ProjNoteField(request.POST or None, instance=formnumber)
if form.is_valid():
form.save()
return HttpResponseRedirect('app/pmhub/')
context = {'form': form}
return render(requset, 'projectinputfields.html', context)

Forms:

class ProjNoteField(forms.ModelForm):
class Meta:
model = Projectsummary
fields = ['projectnote', 'overrunnote']

/r/django
https://redd.it/6cc5vp