background preloader

Django

Facebook Twitter

5. Introduction to Django — Documentation. 6. Django Forms — Documentation. Django and AJAX: Dajax. Tutorial for: Dajax Requirements: Dajax enables you to build web applications using only Python code and HTML, with little to no JavaScript required. This is the third and final tutorial in the Django and AJAX set. This tutorial will focus on building a simple application which uses Dajax to load data from a model and update data back into a model. This tutorial will use some JavaScript, mainly to build the request required when updating or querying objects. For an introduction on what AJAX is and how it works, please refer to the first tutorial in this set.

In order to begin using Dajax, you will need to install Dajaxice. You can change the DAJAXICE_MEDIA_PREFIX to anything you desire, it is used as the virtual directory on your website which serves the AJAX-related views. From django.conf.urls.defaults import patterns, includefrom dajaxice.core import dajaxice_autodiscoverfrom django.conf import settings dajaxice_autodiscover() urlpatterns = patterns('', ...

Fairly straightforward. Doing things with Django forms. By : Shabda Raaj Forms are one of the best features of Django. (After models, admin, url routing etc :) ). Here is a quick tutorial describing how to do things with Django forms. Basic form Prob. You want to show a form, validate it and display it. Ans. Class UserForm(forms.Form): username = forms.CharField() joined_on = forms.DateField() This wil take care that the form is displayed with two text field, and a value for them are filled in, and the second field has correct formatting for a date. Prob. Ans. Class UserForm(forms.Form): username = forms.CharField() plan = forms.ModelChoiceField(queryset = Plan.objects.none()) def __init__(self, subdomain, *args, **kwargs): self.default_username = default_username super(UserForm, self).

Here in the __init__ we are overriding the default queryset on field plan. However the self.fields is populated only after super(UserForm, self). Prob. Ans. Prob. Ans. Here we can validate that the usernames are not repeated. Prob. Ans. Problem. Prob. Ans. Prob. Ans. Two-Faced Django Part 5: JQuery Ajax. We've been spending a lot of time together recently, and you're probably wondering if I'm going to quit writing this series before covering any Ajax at all. That is a very valid concern. But, be reassured, this segment of the tutorial is going to cover using JQuery to implement Ajax voting in our web app. If you haven't followed along with the previous articles, grab the snapshot of the current progress of our project.

Adding JQuery to the web app The first thing we need to do is download JQuery. I recommend grabbing the uncompressed version, because it makes debugging things much more pleasant when you don't have to read minified Javascript... var x = m45(k32, a32);n41(x); What does that mean? Once you have downloaded the library, you're going to want to move it into the polling/media/web/ folder.

Mv jquery-1.2.1.js jquery.js Now we just need to modify our polling/templates/web/base.html file to import the JQuery library. Emacs templates/web/base.html to One task crossed off the todo list. Dajaxproject.com - easy to use ajax libraries for django. AJAX. Pdb: Using the Python debugger in Django - Minutiæ by Mike Tigas. A couple conversations I had at DjangoCon last week reminded me that I’d never gotten around to finishing this little post.

Since I started taking my first iOS development baby steps last year, I’ve become quite dependent on breakpoints and stepping as part of my Objective-C debugging workflow. …And yet, in Python/Django — the stack I spend most of my time working with — I’d stuck to the poor habit of throwing print statements around any found exceptions — for example, to figure out what lies in request.POST for a Django view. And then I came across and started tinkering with pdb. Here’s a brief overview on how to rock your Python debugging workflow by using an actual interactive debugger. The example below highlights the most basic of usecases, but it’s a good start. Using pdb with Django Say, you have a view that looks like this: from django.http import HttpResponse def default(request): # completely innocuous variables foo = 1 bar = 0 # completely innocuous division ni = foo/bar Congrats!

The Django Book. How I Learnt enough Python/Django to be Dangerous in 1 Month. Reading the umpteeth ‘Son, you need to learn to code if you’re going to be a web startup founder’ article I knew it was the first step I had to take. After all, it makes perfect sense right? You have a vague product idea which you want to turn into a prototype or even possibly a V1; you’re either going to need to pay a good developer market rates to do it for you (1000s of dollars of precious startup capital with no guarantee the output will be satisfactory) or you could do it yourself. There is no ‘Technical Co-founder’, it’s a mythical creature that never makes itself known to mere ‘Ideas Guys’. There are just ‘Co-founders’ and all of them need to be building the product at least in the early days.

This is how I went about picking up the skills I required in 1 month. Week 1: Familiarizing Myself with Python Every man and his dog are building their applications in either Python or Ruby. My first port of call was Google’s Python Class. Week 2: Introduction to Django Now You’re Dangerous!