Archive

Author Archive

rotate a matrix

August 22, 2014 Leave a comment

Rotate clockwise:

rotated = zip(*original[::-1])

Rotate counterclockwise:

rotated_ccw = zip(*original)[::-1]

I found this trick in this thread.

[django] awesome Django apps, projects and resources

August 12, 2014 Leave a comment

A curated list of awesome Django apps, projects and resources: https://github.com/rosarior/awesome-django.

Categories: django Tags:

[django] must-watch videos

August 12, 2014 Leave a comment

Must-watch videos about Django (or about Python as applied to Django): https://github.com/rosarior/django-must-watch.

Categories: django Tags: , , ,

[django] Heroku with GoDaddy

August 11, 2014 Leave a comment

Problem
You put your Django project on Heroku and you register a custom domain name for it at GoDaddy. How to assign this domain name to your project on Heroku?

Solution

Categories: django Tags: , , , ,

[django] force HTTPS on Heroku

August 7, 2014 Leave a comment

django-sslify forces SSL on your Django site. It has an excellent documentation, can be set up in a few minutes.

I tried it on Heroku and it works well.

Categories: django Tags: ,

[django] deploy Django on Heroku

August 7, 2014 Leave a comment

https://devcenter.heroku.com/articles/getting-started-with-django

Follow the guide above to deploy your Django project on Heroku.

Categories: django Tags: ,

[webdev] nice CSS buttons

August 4, 2014 Leave a comment

I found some nice CSS3 gradient buttons. Here is a demo with the buttons.

buttons

Categories: web development Tags: ,

[django] create a formatted string with the Django template system

August 4, 2014 Leave a comment

Problem
In an application I wanted to send formatted HTML emails. For producing the body of the email, I wanted to use the Django template system. The task is very similar to creating a view. The difference is that I don’t want to send back the HTML to the client in the browser but I want to store it in a string.

Solution
The solution is very simple:

from django.template.loader import render_to_string

def email():
    context = {'some_key': 'some_value'}
    html = render_to_string('APP_NAME/email.html', context)
    send_email(html)

This tip is from here.

[django] using PostgreSQL for local development

August 4, 2014 Leave a comment

PostgreSQL is highly recommended for Django. In the book “Two Scoops of Django” it is written that you should use the same DBMS that you will use in production. Many people use SQLite3 for local development and PostgreSQL in production but that will lead to surprises. So, if you plan to use PostgreSQL in production, then use PostgreSQL on your localhost too.

Question
How to set up and configure PostgreSQL on localhost? How to make it work with Django?

Answer
I found the answers to these questions here: How To Install and Configure Django with Postgres, Nginx, and Gunicorn.

PostgreSQL for local development
Long version:

# switch to user "postgres"
$ sudo su - postgres
[sudo] password for jabba:
# notice "postgres" in the prompt
postgres@jabba-uplink:~$ createdb mydb

# create a database user if you don't have one yet
postgres@jabba-uplink:~$ createuser myuser -P
Enter password for new role: 
Enter it again:

# grant access
postgres@jabba-uplink:~$ psql
psql (9.3.5)
Type "help" for help.

postgres=# GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
GRANT
postgres=#

Short version (if you already have a database user):

$ sudo su - postgres
postgres$ createdb mydb
postgres$ psql
psql (9.3.5)
Type "help" for help.

postgres=# GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
GRANT
postgres=#
Categories: django Tags: , , ,

[django] init_app.py: complete the initialization of an app.

August 4, 2014 Leave a comment

I wrote a simple script called init_app.py that completes the initialization of a Django application.

You create a new app. like this:

./manage.py startapp APP_NAME

However, the generated app. is far from complete. Put init_app.py next to manage.py (in the same folder) and execute the following command:

./init_app.py APP_NAME

Currently, it performs the following actions:

  • inside the app., create the folder static/APP_NAME
  • inside the app., create the folder templates/APP_NAME
  • inside the app., create a sample urls.py file

Links

Follow

Get every new post delivered to your Inbox.

Join 72 other followers