Let's see the common case when we have form in template and want to save it in the view. 1. Simple POST example The most trivial way is to write the next: #views.py def my_view(request): if request.method == 'POST': form = MyForm(request.POST) if form.is_valid(): form.save() else: form = MyForm() return direct_to_template(request, 'myform.html', {'form' : form}) And the template: <!-- myform.html --> <form id="my-form">{{ csrf_token }} {{ form }} <input type="submit" value="Save form"> </form> Tag {{ csrf_token }} is require...

Hello guys. In this article I'll tell how to add field with captcha image to your Django form (for example, comment form). 1. Installing packages First of all, you'll need PIL installed on your machine with supporting freetype library. Here is the detailed instructions. The next thing is to install django-simple-captcha package. Here is the documentation about it. So, the one thing you should do is to run sudo pip install django-simple-captcha 2. Adding captcha to application In settings.py add captcha to INSTALLED_APPS: # settings.py INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.con...

I've started "Django stories" topic which will highlight django project development process from the begining step by step. In this article we'll describe how to deploy django with python3 to virtualenv. Let's start from virtualenv. So,  virtualenv is an isolated working copy of Python which allows you to work on a specific project without worry of affecting other projects. Install it: apt-get install python3 python-pip pip install virtualenv Create your environment: mkdir /opt/myenv && cd /opt/myenv virtualenv --no-site-packages -p /usr/bin/python3 myenv After this command you'll see next dirs structure: /opt/myenv |...
Published ago by ochirkov

Here is a short recipe for setup Django application with uWSGI server running under Nginx using socket file. I used the following links: http://uwsgi-docs.readthedocs.org/en/latest/Nginx.html http://stackoverflow.com/questions/21820444/nginx-error-13-permission-denied-while-connecting-to-upstream http://projects.unbit.it/uwsgi/wiki/Example So first of all, wsgi.py file has to be existed: import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") # Change this with your settings path from django.core.wsgi import get_wsgi_application application = get_wsgi_application() The next thing is Nginx config. Few lines has to be a...
Published ago by AnaPana

Continuing Alex's idea I decided to describe such useful thing as virtualenwrapper. It allows simple managing of all your virtual environments. Here is its advantages (from the official page): Organizes all of your virtual environments in one place. Wrappers for managing your virtual environments (create, delete, copy). Use a single command to switch between environments. Tab completion for commands that take a virtual environment as argument. User-configurable hooks for all operations. Plugin system for more creating sharable extensions. 1. Installation $ pip install virtualenvwrapper $ export WORKON_HOME=~/venvs # make variable for path to your virtual ...
Published ago by AnaPana

There were few changes in application structure on Openshift after its last release (https://blog.openshift.com/openshift-online-march-2014-release-blog/). Because of this I had some troubles with creating new Django application. Here I will describe steps for creating Django 1.7 application using Python 2.7 cartridge on Openshift. 1. Create application There are two options for creating application on Openshift: using command line tools  using GUI  Both of these are described here https://developers.openshift.com/en/getting-started-overview.html#step3 2. Clone application to development machine Create empty Git repository on your machine: mkdir ...
Published ago by AnaPana

There are several ways to organize your production settings in Django. Of course it's up to you which way to  chose. 1. Separate files Some developers like to separate production/test/dev settings in different files. This is quite convenient approach if you don't have to mess with them very often. In this case there is base file base.py which contains all common settings for all environments. So assume that our Django project's structure is: . |-- README.md |-- prj_name/ | |-- settings | | |-- __init__.py | | |-- base.py | | |-- dev.py | | |-- prod.py | | |-- test.py | |-- urls.py | |-- wsgi.py |-- some_app/ ... I...
Published ago by AnaPana

Python
Web development
Review Linux
Administration
Provisioning CVS
Windows AWS
Continuous Integration
NoSql Logging Web Servers FileSystems Scala
accurev ansible apach2 apache api application approaches architecture archivation argparse arguments artifactory automation awk aws backup bash batch-scripting beaver block build built-in caching call captcha cartridge case certificates cgi chain client cloud cloudformation cluster cmd coding collections command-line commands compression conditionals conversion convert cookbook copy counter cron crud css cut cygwin daemon datatype date dd debpackage decorator delattr deploy deque dict distributed-file-systems django DNS domain driver dropbox dump elasticcache elasticsearch encryption exit ext4 extra-tags failover file filename filters for form format freetds functions gerrit getattribute gid git globals glusterfs hardware hook iam indexing inheritance init install job-interview jquery ldap linux list locals logging logs logstash lookup magicmethods mail main-menu metadata metalogger mongodb moosefs mount mssql multiplatform multithreading mysql netcat nginx nosql open-ssh openldap openshift os packaging parse partition path pattern patterns permissions pid pil pip pipe playbook pool post post-commit processes production provisioning proxy putty python python-mysql recursively redirection redis register replication repr restore return review rotation scala script search selenium server setattr settings setup shipper signals singleton slots snapshot socket splunk ssh ssh-key ssl storage str string style subprocess sugar super switch syntactic syntaxhighlighter systeminfo tail tar templatetags time tls tune2fs tuple ubuntu unicode unique unix unixodbc usage usecases uuid uwsgi variable vars version vi virtualenv volume web web-server windows with_items __getattr__