Hi, I'm Daniel Greenfeld, and welcome to my blog. I write about Python, Django, and much more.

Core Concepts of Django Forms

Friday, March 29, 2013 (permalink)

In my opinion, the concepts behind Django's non-model forms can be listed in just three (3) bullets:

  • Forms render HTML.
  • Forms are "just" Python constructs.
  • Forms validate dictionaries (Python's Key/Value structure).

Let's dig in!

Forms render HTML.

If I construct a Django form:

# myapp/forms.py ...
Read more ...

Stay with the Django CBV defaults!

Tuesday, November 27, 2012 (permalink)

One virtue of Django Class Based Views (CBVs) is that they come with pretty good default settings. The virtue of this is you can really pare your code down in size and complexity.

For example, here is an implementation of CBVs based on a straight-forward Django model , stuffage.models.Stuff ...

Read more ...

Case Study: URL Design for petcheatsheets.com

Wednesday, November 21, 2012 (permalink)

Backstory: On Saturday, November 17, 2012 Audrey Roy and I decided to participate in the Petcentric hackathon, a Los Angeles area Pet-themed product/coding contest held at Amplify. We arrived a bit late, but armed with Audrey's idea of creating a pet based reference sheet for owners, pet sitters ...

Read more ...

Django GetOrCreateView

Tuesday, October 16, 2012 (permalink)

Today I decided to use the Django class based view (CBV) CreateView, but I wanted to avoid duplications and submit to the view from the front page of a site. The reason was I needed a simple newsletter signup form. This is what I cooked up and should work for ...

Read more ...

Django Update View without slug in the url

Saturday, July 28, 2012 (permalink)

Today I wanted to use the Django Class Based View (CBV) UpdateView but without a slug identifier in the URL. For example, instead of /profiles/pydanny/ I would go to /my-crazy-profile/. Also, I needed to force authentication.

I've done this with Django functional views a few times times, but ...

Read more ...

Django Class Based View: email form with CAPTCHA

Wednesday, May 23, 2012 (permalink)

Yesterday I showed how to implement a simple email form for Django using Class Based Views. Today I'm going to extend yesterday's work to use the excellent RECAPTCHA service to help reduce spam content.

This version requires pip installing the following into your virtualenv.

  • pip install django-crispy-forms so ...
Read more ...

Simple Django email form using CBV

Tuesday, May 22, 2012 (permalink)

Here's a simple FormView Class Based Views for Django. Here is a sample of how to do one as a simple email form. There is no CAPTCHA in this example, that's the topic of a future blog post.

This version requires the following packages pip installed into your ...

Read more ...