Below you will find pages that utilize the taxonomy term “Python”
Django and NGINX in Docker
In this post we will run Django application behind a NGINX webserver, which is a very common practice in production.
Django CRUD (Create, Retrieve, Update, Delete)
One of the most common task when developing web application is to write create, read, update and delete functionality (CRUD) for each table you have.
In this post I briefly cover the step needed to create a CRUD app in Django, the steps we will need are:
Django with Docker: Add Postgres
In the last post I covered starting a new Django project with Docker, and how to build a custom container image for my project, but what I haven’t covered is how to use a Database and how persist your data since all data stored in the container ephemeral and would only exist during the life span of the container.
Django with Docker: Build an Image
Docker is an interesting technology, although still young it gained a lot of buzz and momentum.
The last couple of weeks I started playing with Docker to see how can I use it for Django project development and deployment.
Django: How to pass an url as parameter of include
My first public Python Package “pyagentx”
Django Image and File Field Caveats
Install psycopg2 (PostgreSQL adapter for Python) on OSX
Solving Python virtualenv “DistributionNotFound: distribute”
After upgrading my Ubuntu machine from 12.04 to 14.04 I had this error on virtualenv wrapper:
Django Themes (or where to put base.html?)
The Wrong Way
I used to create a new directory to hold common templates like “base.html”, and add it TEMPLATES_DIR in the settings.py file:
Django returning JSON for AJAX requests
In your views.py
you can have a page that return JSON data for AJAX request like this:
Setting Up Python and Supervisor on CentOS
CentOS default repository is very limited, and even if you install EPEL you will get old packages, in my case I needed to install Supervisor to manage my Django application, after trying to do it manually and through EPEL I ended up with the following setup.
Django Multiple Settings with Single File
Instead of having multiple settings files one for production and one for development and so on, I prefer to use an “if” statement with environment variable:
Django “render” vs “render_to_response”
Summary: Always use render
and not render_to_response
In Django you have more than one way to return a response, but many times I get confused between render
and render_to_response
, render_to_response seems shorter, so why not use it!
Install Python Image Library (PIL) on OSX
PIL or Python Imaging Library is a library that allows you to manipulate images in Python programming language, trying to install “PIL” using “pip” tool won’t work perfectly so here is how to proper installation.
My New Project: AgentX Implementation in Python
During this Eid vacation I spent many hours working on AgentX implementation in Python.
You can find the project in GitHub:
Python auto complete in OSX
If you run Python shell in OSX you notice the auto completion functionality isn’t working, this is caused by Apple decision not to ship GNU readline and instead they use libedit (BSD license), to fix the problem I used the following snippet:
IPython Import Error
I tried to install IPython to play with it and learn more about scientific Python packages, but I faced an error on my first step:
Implementing Login/Logout in Django
Update: add names and namespace to URLs
Implementing user authentication is fairly easy job in Django, many functionalities are already included in the standard Django installation, you can manage users using the default “admin” app the comes with Django.
Here I will show how implement Login/Logout feature by relying on Django built-in views.
Django Serving Static Files without a Web Server
Managing Python Environments with “virtualenvwrapper”
What is virtualenvwrapper
virtualenvwrapper is a tool that (as the name suggest) wrap “virtualenv” program, virtualenv solve the following problem:
Minimal Django Project: Part 2 … Flat Pages
Minimal Django Project: Part 1 … First Run
My Python and Django bookmarks
Deploying Django
Django is a web framework written in Python language, my favourite computer programming language.
Python a language is really great language, easy to read and understand, and very easy to learn, but for me I always found setting up Python for web development as a challenge, socially if compare it to PHP, which almost works out of the box, actually most people think PHP works only in the web server and can’t work as stand alone application, search for PHP CLI if you are interested.
I will try here to document an easy Django deployment for my future reference and hopefully it will help others: