Below you will find pages that utilize the taxonomy term “django”
Blog
ImportError: Reportlab Version 2.1+ is needed
Little bug in xhtml2pdf version 0.0.5. To fix:
$ sudo nano /usr/local/lib/python2.7/dist-packages/xhtml2pdf/util.py Change the following lines:
1if not (reportlab.Version[0] == "2" and reportlab.Version[2] >= "1"): 2 raise ImportError("Reportlab Version 2.1+ is needed!") 3 4REPORTLAB22 = (reportlab.Version[0] == "2" and reportlab.Version[2] >= "2") With these lines:
1if not (reportlab.Version[:3] >= "2.1"): 2 raise ImportError("Reportlab Version 2.1+ is needed!") 3 4REPORTLAB22 = (reportlab.Version[:3] >= "2.1")
Blog
Django Migrations Table Already Exists Fix
Fix this issue by faking the migrations:
python manage.py migrate –fake <appname> Taken from this SO answer
Blog
Mezzanine BS Banners Translation with django-modeltranslation
Mezzanine BS Banners is a nice app for implementing Bootstrap 3 banners/sliders to your Mezzanine projects. The Banners model in BS Banners app has a title and its stacked inline Slides model has title and content for translation.
After [installing and setting up Django/Mezzanine translations]({% post_url 2015-07-01-djangomezzanine-content-translation-for-mezzanine %}):
Create a translation.py inside your Mezzanine project or your custom theme/skin application and copy/paste following lines:
1from modeltranslation.translator import translator 2from mezzanine.core.translation import TranslatedSlugged, TranslatedRichText 3from mezzanine_bsbanners.
Blog
Django/Mezzanine Content Translation for Mezzanine Built-in Applications
As Mezzanine comes with additional Django applications such as pages, galleries and to translate their content, Mezzanine supports django-modeltranslation integration.
Install django-modeltranslation:
pip install django-modeltranslation Add following to the INSTALLED_APPS in settings.py:
1"modeltranslation", And following in settings.py:
1USE_MODELTRANSLATION = True Also, move mezzanine.pages to the top of other Mezzanine apps in INSTALLED_APPS in settings.py like so:
1"mezzanine.pages", 2"mezzanine.boot", 3"mezzanine.conf", 4"mezzanine.core", 5"mezzanine.generic", 6"mezzanine.blog", 7"mezzanine.forms", 8"mezzanine.galleries", 9"mezzanine.twitter", 10"mezzanine.accounts", 11"mezzanine.mobile", Run following to create fields in database tables for translations:
Blog
Setting Up Templates and Python Scripts for Translation
Templates need following template tag:
1{% raw %}{% load i18n %}{% endraw %} Then, wrapping any text with
1{% raw %}{% trans "TEXT" %}{% endraw %} will make it translatable via Rosetta Django application
In Python scripts, you need to import following library:
from django.utils.translation import ugettext_lazy as _ Then wrapping any text with
1_('TEXT') will make it translatable.
Blog
Django Rosetta Translations for Django Applications
Make a directory called locale/ under the application directory:
cd app_name mkdir locale Add the folder in LOCAL_PATHS dictionary in settings.py:
1LOCALE_PATHS = ( 2 os.path.join(PROJECT_ROOT, 'app_name', 'locale/'), 3) Run the following command to create PO translation file for the application:
python ../manage.py makemessages -l tr -e html,py,txt python ../manage.py compilemessages Option -l is for language, it should match your definition in settings.py:
1LANGUAGES = ( 2 ('en' _('English')), 3 ('tr' _('Turkish')), 4 ('it' _('Italian')), 5) Repeat the last step for all languages and the go to Rosetta URL to translate.
Blog
Django Rosetta Installation
Install SciPy:
sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy python-nose Install pymongo and nltk:
sudo pip install pymongo sudo pip install nltk Install Python MySQLdb:
sudo apt-get install python-mysqldb Install Rosetta:
sudo pip install django-rosetta Add following into INSTALLED_APPS in settings.py:
1"rosetta", Add following into urls.py:
url(r’^translations/’, include(‘rosetta.urls’)), To also allow language prefixes , change patters to i18n_patterns in urls.py:
1urlpatterns += i18n_patterns( 2 ... 3)
Blog
Errno 13 Permission denied Django File Uploads
Run following command to give www-data permissions to static folder and all its content:
cd path/to/your/django/project sudo chown -R www-data:www-data static/ Do this in your production server
Blog
Configuring Mezzanine for Apache server & mod_wsgi in AWS
Install [Mezzanine]({% post_url 2015-05-01-how-to-install-mezzanine-on-ubuntulinux-mint %}), [Apache server]({% post_url 2015-05-08-getting-started-with-your-aws-instance-and %}) and mod_wsgi:
sudo apt-get install libapache2-mod-wsgi sudo a2enmod wsgi Set up a MySQL database for your Mezzanine project
Read [my post on how to set up a MySQL database for a Mezzanine project]({% post_url 2015-05-09-how-to-set-up-a-mysql-database-for-a-mezzanine %})
Collect static files:
python manage.py collectstatic Configure your Apache server configuration for the project like following:
WSGIPythonPath /home/ubuntu/www/mezzanine-project <VirtualHost *:80> #ServerName example.com ServerAdmin admin@example.com DocumentRoot /home/ubuntu/www/mezzanine-project WSGIScriptAlias / /home/ubuntu/www/mezzanine-project/wsgi.
Blog
How to Set Up a MySQL Database for a Mezzanine Project
Install MySQL server and python-mysqldb package:
sudo apt-get install mysql-server sudo apt-get install python-mysqldb Run MySQL:
mysql -u root -p Create a database:
mysql> create database mezzanine_project; Confirm it:
mysql> show databases; Exit:
mysql> exit Configure local_settings.py:
cd path/to/your/mezzanine/projectnano local_settings.py Like following:
1DATABASES = { 2 "default": { 3 "ENGINE": "django.db.backends.mysql", 4 "NAME": "mezzanine_project", 5 "USER": "root", 6 "PASSWORD": "123456", 7 "HOST": "", 8 "PORT": "", 9 } 10 } Note: Replace your password
Blog
How to Install Mezzanine on Ubuntu/Linux Mint [Complete Guide]
Mezzanine is a CMS application built on Django web framework. The installation steps are easy but your environment may not just suitable enough for it work without a problem. So, here I’m going to describe complete installation from scratch on a virtual environment.
First of all, install virtualenv:
$ sudo apt-get install python-virtualenv Then, create a virtual environment:
$ virtualenv testenv And, activate it: $ cd testenv $ source bin/activate
Blog
How to Clear (or Drop) DB Table of A Django App
Let’s say you created a Django app and ran python manage.py syncdb and created its table. Everytime you make a change in the table, you’ll need to drop that table and run python manage.py syncdb again to update. And how you drop a table of a Django app:
$ python manage.py sqlclear app_name | python manage.py dbshell Drop tables of an app with migrations (Django >= 1.8):
$ python manage.py migrate appname zero Recreate all the tables: