Saturday, July 24, 2010

Django on Google App Engine

In case that you want to run the head (latest version) of django on the google app engine this will help you. The info bellow is for a new project (in case you need information on how to make it work with an
existing project see the README file from the appengine_helper).

First you need to understand what is different between running django on your server where you have a RDBMS like mysql and the datastore that google provides. To do this look into the following link
http://code.google.com/appengine/articles/appengine_helper_for_django.html

After you are done reading do the following:
(i'm using /tmp as an example, you can change it to whatever you want)

cd /tmp/

- download the appengine_helper_for_django (if the link changed because there is a new version replace bellow the names for helper with the new names)

curl -L -o 'appengine_helper_for_django-r105.zip' 'http://google-app-engine-django.googlecode.com/files/appengine_helper_for_django-r105.zip'


- download  the latest version of django (you can download it or use the svn to checkout)

curl -L -o 'Django-1.2.1.tar.gz' 'http://www.djangoproject.com/download/1.2.1/tarball/'


- untar the django

tar xvfz Django-1.2.1.tar.gz


- make a new temporary directory for your application

mkdir myapp_tmp


- extract the django helper 

cd myapp_tmp
unzip ../appengine_helper_for_django-r105.zip


- rename the helper

mv appengine_helper_for_django/ myapp


- copy the django framework to have it available

cp  -r ../Django-1.2.1/django  myapp


- configure the app and run the webserver

cd myapp
ls    (you should have something like this)


HANGES VERSION appengine_django manage.py urls.pyc
COPYING __init__.py django settings.py
KNOWN_ISSUES __init__.pyc index.yaml settings.pyc
README app.yaml main.py urls.py


- edit the app.yaml to reflect your application name etc.


- run the webserver to test

python manage.py runserver
(you should see the output from the app engine starting)

"""

/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/datastore_file_stub.py:40: DeprecationWarning: the md5 module is deprecated; use hashlib instead
  import md5
/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/memcache/__init__.py:31: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
  import sha
WARNING:root:Could not read datastore data from /var/folders/TI/TIS6v9poFPyMZ3GaFkfkjE+++TQ/-Tmp-/django_vpsup.datastore
WARNING:root:Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging
INFO:google.appengine.tools.appengine_rpc:Server: appengine.google.com
INFO:root:Checking for updates to the SDK.
INFO:root:The SDK is up to date.
"""

that's it ! you can start using django as you normally do.

(in case you want to change the location of your myapp directory all you have to do is to move the myapp to the new destination - mv /tmp/myapp_tmp/myapp /home/myuser/applications/myapp)









Monday, July 12, 2010

URL - safe and unsafe characters

"Unsafe characters"
    
Why:
Some characters present the possibility of being misunderstood within URLs for various reasons. These characters should also always be encoded.
Characters:
Character
Code
Points
(Hex)
Code
Points
(Dec)
Why encode?
Space
20
32
Significant sequences of spaces may be lost in some uses (especially multiple spaces)
Quotation marks
'Less Than' symbol ("<")
'Greater Than' symbol (">")
22
3C
3E
34
60
62
These characters are often used to delimit URLs in plain text.
'Pound' character ("#")
23
35
This is used in URLs to indicate where a fragment identifier (bookmarks/anchors in HTML) begins.
Percent character ("%")
25
37
This is used to URL encode/escape other characters, so it should itself also be encoded.
Misc. characters:
   Left Curly Brace ("{")
   Right Curly Brace ("}")
   Vertical Bar/Pipe ("|")
   Backslash ("\")
   Caret ("^")
   Tilde ("~")
   Left Square Bracket ("[")
   Right Square Bracket ("]")
   Grave Accent ("`")

7B
7D
7C
5C
5E
7E
5B
5D
60

123
125
124
92
94
126
91
93
96
Some systems can possibly modify these characters.

"Reserved characters"
    
Why:
URLs use some characters for special use in defining their syntax. When these characters are not used in their special role inside a URL, they need to be encoded.
Characters:
Character
Code
Points
(Hex)
Code
Points
(Dec)
 Dollar ("$")
 Ampersand ("&")
 Plus ("+")
 Comma (",")
 Forward slash/Virgule ("/")
 Colon (":")
 Semi-colon (";")
 Equals ("=")
 Question mark ("?")
 'At' symbol ("@")
24
26
2B
2C
2F
3A
3B
3D
3F
40
36
38
43
44
47
58
59
61
63
64