Archive
rotate a matrix
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
A curated list of awesome Django apps, projects and resources: https://github.com/rosarior/awesome-django.
[django] must-watch videos
Must-watch videos about Django (or about Python as applied to Django): https://github.com/rosarior/django-must-watch.
[django] Heroku with GoDaddy
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
- Heroku with GoDaddy @lifesforlearning.com (excellent)
- Setup Heroku and GoDaddy? @SO
[django] force HTTPS on Heroku
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.
[django] deploy Django on Heroku
Follow the guide above to deploy your Django project on Heroku.
[webdev] nice CSS buttons
I found some nice CSS3 gradient buttons. Here is a demo with the buttons.
[django] create a formatted string with the Django template system
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
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=#
[django] init_app.py: complete the initialization of an app.
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.pyfile
Links


You must be logged in to post a comment.