Wednesday, September 14, 2011

Josm editor User Manual PDF

I want to use Josm editor for a project. But it seems there is no pdf version of the entire user manual. So I create this pdf file and share online. It can be downloaded here

Wednesday, September 7, 2011

How To Install Python + Django + Aptana Studio on Windows 7

In this article, I will explain how to get Python, Django, and Aptana Studio running smoothly on windows.

1. Install Python


  •  Go to http://www.python.org/download/ and download the Python. I am currently using the 2.7 version. Note that the latest version may not work with Windows yet.
  •  Execute and install what you’ve just downloaded with the default options
  • open command window and type 'python' to test if it is successfully installed. If command not recognized, follow these steps to add the path in Windows 7. Start -> Control Panel -> System and Security->Systems-> Advanced system settings->Environment Variables-> System Variables -> PATH->modify PATH by appending ;C:\Python27;C:\Python27\Scripts”. Also make sure you have a semicolon (;) before what you write.
2. Installing Django
  • Go to http://www.djangoproject.com/download/ and download the version that best suits you. Version 1.3 works fine for me.
  • Extract the files to a folder. WinZip will do the job. Please REMEMBER THE FOLDER WHERE YOU EXTRACTED DJANGO.
  • Open a command prompt (Start > Run > Type in “cmd” and press OK). In the black window that is going to show up, type in cd “[directory_of_django]“. For example: cd "C:\www\python\Django-1.3″. 
  • setup.py install
3. Installing aptana studio
Aptana studio is a version of eclipse that already comes with HTML and CSS editors, and installing PyDev in it is really easy.
  • Go to http://www.aptana.org/studio/download and download the standalone full installer version.
  • go to Window > Preferences > PyDev > Interpreter – Python and click “Auto-Config”
  • Click OK on everything else
4. Installing MySQL for Python
If you are going to use django with MySQL, you will probably need to perform those steps:
  • Go to http://www.codegood.com/downloads and download
  • MySQL-python-1.2.2.win32-py2.6.exe, if you have a 32 bit OS or MySQL-python-1.2.2.win-amd64-py2.6.exe, if you have a 64 bit OS. In doubt, download the first one.
  • Install it.
Have fun!

Tuesday, September 6, 2011

Django Csrf verification failed


The first problem is met when I am connecting Django with MySql.
Installing MySqldb (or MySql-python) from the site:

The second problem is Forbidden (403) CSRF verification failed. Request aborted.
Assuming everything else is fine.
The solution is to add into "settings.py=>MIDDLEWARE_CLASSES"
the line
'django.middleware.csrf.CsrfResponseMiddleware',



How to use CSRF

To enable CSRF protection for your views, follow these steps:
  1. Add the middleware 'django.middleware.csrf.CsrfViewMiddleware' to your list of middleware classes,MIDDLEWARE_CLASSES. (It should come and before any view middleware that assume that CSRF attacks have been dealt with.)
    Alternatively, you can use the decorator csrf_protect() on particular views you want to protect (see below).
  2. In any template that uses a POST form, use the csrf_token tag inside the
    element if the form is for an internal URL, e.g.:
    {% csrf_token %}
    This should not be done for POST forms that target external URLs, since that would cause the CSRF token to be leaked, leading to a vulnerability.
  3. In the corresponding view functions, ensure that the 'django.core.context_processors.csrf' context processor is being used. Usually, this can be done in one of two ways:
    1. Use RequestContext, which always uses 'django.core.context_processors.csrf' (no matter what your TEMPLATE_CONTEXT_PROCESSORS setting). If you are using generic views or contrib apps, you are covered already, since these apps use RequestContext throughout.
    2. Manually import and use the processor to generate the CSRF token and add it to the template context. e.g.:
      from django.core.context_processors import csrf from django.shortcuts import render_to_response  def my_view(request):     c = {}     c.update(csrf(request))     # ... view code here     return render_to_response("a_template.html", c) 
      You may want to write your own render_to_response() wrapper that takes care of this step for you.
The utility script extras/csrf_migration_helper.py can help to automate the finding of code and templates that may need these steps. It contains full help on how to use it.