Saturday, 24 May 2014

ImproperlyConfigured: dh5bp doesn't look like a module path (Django/html5)

Add this to your urls.py at the top :

from dh5bp.urls import urlpatterns as dh5bp_urls

apache2: [warn] The Alias directive in /etc/apache2/sites-enabled/httpd at line 47 will probably never match because it overlaps an earlier Alias.

Apache shows this warning because the user may used two Alias for the same path in the Apache configuration files. In my case i used two alias  given as follows:

        Alias /static/ /home/user/site/static/

        <Directory /home/user/site/static>
        Order deny,allow
        Allow from all
        </Directory>

and

         Alias /static/ /home/user/site/static/
         <Location "/static/">
             Options -Indexes
         </Location>

So, i removed the second one.

Friday, 23 May 2014

Deploy Django with apache2 in Virtualenvs

Virtual Hosts


Apache2 has the concept of sites, which are separate configuration files that Apache2 will read. These are available in /etc/apache2/sites-available. By default, there is one site available called 000-default. This is what you will see when you browse to http://localhost or http://127.0.0.1. You can have many different site configurations available, and activate only those that you need.
As an example, we want the default site to be /home/user/public_html/. To do this, we must create a new site and then enable it in Apache2.
To create a new site:
  • Copy the default website as a starting point. sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/mysite.conf 
  • Edit the new configuration file in a text editor "sudo nano" on the command line or "gksudo gedit", for example: gksudo gedit /etc/apache2/sites-available/mysite.conf
  • Change the DocumentRoot to point to the new location. For example, /home/user/public_html/
  • Change the Directory directive, replace <Directory /var/www/> to <Directory /home/user/public_html/>
  • You can also set separate logs for each site. To do this, change the ErrorLog and CustomLog directives. This is optional, but handy if you have many sites
  • Save the file
Now, we must deactivate the old site, and activate our new one. Ubuntu provides two small utilities that take care of this: a2ensite (apache2enable site) and a2dissite (apache2disable site). 

$ sudo a2dissite 000-default && sudo a2ensite mysite
 
$ sudo /etc/init.d/apache2 restart
 
If you have not created /home/user/public_html/, you will receive an warning message
To test the new site, create a file in /home/user/public_html/

$ echo '<b>Hello! It is working!</b>' > /home/user/public_html/index.html
 
Finally, browse to http://localhost/ 
 
 
 CONFIGURE DJANGO TO APACHE
$ vim /etc/apache2/sites-available/mysite
 
Inside mysite 

        WSGIPythonPath /home/user/site:/home/user/.virtualenvs/test/lib/python2.7/site-packages
        WSGIPythonHome /home/user/.virtualenvs/test
<VirtualHost *:80>

        <Directory /home/user/.virtualenvs/test/lib/python2.7/site-packages>
        Options Indexes
        Order deny,allow
        Allow from all
        </Directory>

      
        WSGIScriptAlias /site /home/user/site/site/wsgi.py
        <Directory /home/user/site/site>
        <Files wsgi.py>
        Order deny,allow
        Allow from all
        </Files>
        </Directory>

        Alias /static/ /home/user/site/static/
        <Location "/static/">
            Options -Indexes
        </Location > 
</VirtualHost>

Thursday, 22 May 2014

To find a file in linux terminal

find ~/ -type f -name <file_name>

Installing mysq-python with virtualevns

The error may be:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb


Solution:

$ sudo apt-get install libmysqlclient-dev
 
$ sudo apt-get install python-dev 

pip install mysql-python
 
ENJOY!!!!!!! 

Creating Virtualenv for Django project.

Install distribute and pip

curl -O http://python-distribute.org/distribute_setup.py
sudo python distribute_setup.py
sudo easy_install pip
 
pip completion --bash >> ~/.bashrc

and run source ~/.bashrc to enable

Use pip to install virtualenv and virtualenvwrapper

sudo pip install virtualenv
sudo pip install virtualenvwrapper
 
export WORKON_HOME=`~/.virtualenvs`
 
mkdir $WORKON_HOME
 
echo "export WORKON_HOME=$WORKON_HOME" >> ~/.bashrc
 
Setup virtualenvwrapper
 
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
echo "export PIP_VIRTUALENV_BASE=$WORKON_HOME" >> ~/.bashrc       

Source ~/.bashrc to load the changes

source ~/.bashrc

Test if it works

Now we create our first virtual environment
 
mkvirtualenv test

You will see that the environment will be set up, and your prompt now includes the name of your active environment in parentheses. Also if you now run
 
python -c "import sys; print sys.path"

you should see a lot of /home/user/.virtualenv/... because it now doesn't use your system site-packages.

You can deactivate your environment by running
 
deactivate

and if you want to work on it again, simply type
 
workon test

Finally, if you want to delete your environment, type
 
rmvirtualenv test
 
 
To Install Django  

$ pip install django
$ which django-admin.py
$ django-admin.py startproject django_project
 
ENJOY!!!!!! 

Sunday, 10 February 2013

"The STATICFILES_DIRS setting should " django.core.exceptions.ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting


The problem is that you have your STATIC_ROOT as one of the STATICFILES_DIRS. The STATIC_ROOT directory should be empty, that is where all the static files from different places will be gathered when you run collectstatic. You should probably create a static directory under the myapp directory and move all your static files there. Leave the STATIC_ROOT setting as you have it now, and don't specify STATICFILES_DIRS. By default django looks in static directories under all apps in INSTALLED_APPS. 

For more information please refer this discussion: https://mail.google.com/mail/ca/?shva=1#sent/13cc5c3b876dcb8d