A web developer's blog. PHP, MySQL, CakePHP, Zend Framework, Wordpress, Code Igniter, Django, Python, CSS, Javascript, jQuery, Knockout.js, and other web development topics.

Tag Archives: python

Django: Creating multiple select checkboxes with Forms

I got stuck for almost an hour trying to create a multiple select checkbox. Here is how to do it: First, I put this in my forms.py class UserlistForm(forms.Form): users = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,label="Notify and subscribe users to this post:") Then in … Continue reading

Posted in General | Tagged , , , , | 3 Comments

Python: Saving a file from the URL by chunks

For example, when you want to save an image from a URL. https://github.com/images/modules/header/logov3-hover.png f = urllib.urlopen(request.POST[’url’]) p = os.path.join(settings.UPLOAD_DIRECTORY, "saved_file.jpg") filesize = 0 with open(p,’wb’) as output: while True: buf = f.read(65536) filesize += len(buf) if not buf: break output.write(buf)

Posted in General | Tagged | Leave a comment

Django: Reading an image outside the public accessible directory and displaying the image through the browser

In some cases you would want to have “private” images for your logged-in users, you will not be able to store the images in the public accessible directory. For example, if you have “my_private_photo.png” stored in your normal “images” directory, … Continue reading

Posted in General | Tagged , , | 1 Comment

File Streaming in Django (Sending large files through Django)

I am planning to build something involving serving large files over HTTP. Putting the files in a public accessible directory is not an option since I need to monitor the users who download the file. Users will need to login … Continue reading

Posted in General | Tagged , , , | 3 Comments

A Simple Tkinter Example (Python)

What is Tkinter? Tkinter is Python’s de-facto standard GUI (Graphical User Interface) package. It is a thin object-oriented layer on top of Tcl/Tk. Here is a simple Tkinter example. The code below should generate a very simple GUI with a … Continue reading

Posted in General | Tagged , | 2 Comments

A Basic Python Class

This is the basic structure of a Python class. >>> class Simplex: … "An example class""" … def __init__(self, x, y): … self.a = x … self.b = y … def addition(self): … return self.a + self.b … >>> z … Continue reading

Posted in General | Tagged , , , | 1 Comment

My notes for Lists in Python

Lists A list is a sequence of values. [ and ] like numerically indexed arrays in PHP >>> # a list of numbers >>> my_numbers = [10, 15, 20, 25] >>> print my_numbers [10, 15, 20, 25] >>> >>> #a … Continue reading

Posted in General | Tagged , | 2 Comments

Basic Python: Filenames and paths

Another Python post! I am still learning the language. Since I cannot remember everything, I am posting it here for future reference. Get the Current Working Directory To get the “current working directory” do this: import os current_dir = os.getcwd() … Continue reading

Posted in General | Tagged , , , , , , , | Leave a comment

My Google App Engine Application

I just got this in my email: Hello, Thanks for signing up to try Google App Engine! Your account has been activated, so you can begin building applications! To start creating applications with Google App Engine, simply follow this link … Continue reading

Posted in General | Tagged , , | 4 Comments