{"id":123,"date":"2012-06-01T12:58:49","date_gmt":"2012-06-01T16:58:49","guid":{"rendered":"http:\/\/lichun.cc\/blog\/?p=123"},"modified":"2012-06-01T12:58:49","modified_gmt":"2012-06-01T16:58:49","slug":"setup-django-1-4-on-godaddy-linux-economy-host","status":"publish","type":"post","link":"https:\/\/www.lichun.cc\/blog\/2012\/06\/setup-django-1-4-on-godaddy-linux-economy-host\/","title":{"rendered":"setup Django 1.4 on Godaddy linux economy host"},"content":{"rendered":"<p>In case you want to use Django framework in Godaddy&#8217;s Linux Economy Host, here is the steps:<\/p>\n<p>1. Godaddy has <strong>virtualenv<\/strong> installed, so first, create a virtual environment <strong>venv<\/strong>: (I use <strong>$HOME\/lib\/<\/strong> for all the installed stuff below)<\/p>\n<pre>cd ~\/\nmkdir lib\ncd lib\nvirtualenv --no-site-packages venv<\/pre>\n<p>The python package folder is <b>$HOME\/lib\/venv\/lib\/python2.7\/site-packages<\/b><\/p>\n<p>2. Install the latest Django through <strong>pip<\/strong><br \/>\n<code>pip install Django<\/code><\/p>\n<p><!--more--><\/p>\n<p>3. After successfully installed Django 1.4, create a new project<br \/>\n<code>django-admin.py startproject mysite<\/code><\/p>\n<p>4. Because Django 1.4 only support MySQLdb 1.2.1 or above, and Godaddy only has 1.2.0, so we cannot use MySQL. Let&#8217;s use <strong>sqlite<\/strong> for our database<\/p>\n<pre>cd mysite\nsqlite3 mydatabase.db \"\"<\/pre>\n<p>5. change the database configuration in <strong>mysite\/setting.py<\/strong> file<br \/>\n(1) when set the path for the database file, please <strong>use the absolute path<\/strong><br \/>\n(2) set the <strong>Locale<\/strong> information in <strong>$HOME\/.bash_profile<\/strong> file, otherwise you cannot set the superuser when you sync the database.<\/p>\n<pre>    export LANG=en_US.UTF-8\n    export LC_ALL=en_US.UTF-8<\/pre>\n<p>run <strong>$HOME\/.bash_profile<\/strong>:<\/p>\n<pre>% source ~\/.bash_profile<\/pre>\n<p>(3) now you should sync the database:<br \/>\n<code>% python2.7 manage.py syncdb<\/code><br \/>\nThere should be no error if you did (2)<\/p>\n<p>6. Now we setup the <strong>dispatch<\/strong> functionality so we can access the webpage without running server through Django, we use <b>flup<\/b> here<\/p>\n<pre>\ncd ~\/lib\/venv\/lib\/python2.7\/site-packages\nwget http:\/\/pypi.python.org\/packages\/source\/f\/flup\/flup-1.0.2.tar.gz#md5=24dad7edc5ada31dddd49456ee8d5254\ntar -xvzf flup-1.0.2.tar.gz\nmv flup-1.0.2\/flup\/ .<\/pre>\n<p>And you can delete the <strong>flup-1.0.2<\/strong> folder if you want.<\/p>\n<p>7. in <strong>$HOME\/html<\/strong> folder, create <strong>dispatch.py<\/strong> and add the following codes:<\/p>\n<pre>#!\/usr\/local\/bin\/python2.7\nimport sys, os\nsys.path += ['\/your\/home\/path\/lib\/venv\/lib\/python2.7\/site-packages']\nsys.path += ['\/your\/home\/path\/lib\/mysite\/']\nos.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'\n\nfrom flup.server.fcgi import WSGIServer\nfrom django.core.handlers.wsgi import WSGIHandler\nWSGIServer(WSGIHandler()).run()<\/pre>\n<p>8. in <strong>$HOME\/html\/.htaccess<\/strong> file, add the following codes:<\/p>\n<pre>AddHandler fcgid-script .fcgi\nOptions +FollowSymLinks\nRewriteEngine On\nRewriteBase \/\n\n# everything else sent to django\nRewriteRule ^(dispatch.py\/.*)$ - [L]\nRewriteRule ^(.*)$ dispatch.py\/$1 [L]<\/pre>\n<p>9. Access your website <strong>http:\/\/your.website.com<\/strong>, it should work<\/p>\n<h2><span style=\"color: #ff6600;\">addtional<\/span><\/h2>\n<p>1. add <strong>static<\/strong> path in <strong>mysite\/settings.py<\/strong>, so Godaddy host can read the static folder correctly<\/p>\n<pre>from django.conf import settings\n\nurlpatterns = patterns('',\n    url(r'^static\/(?P.*)$', 'django.views.static.serve',\n\t{'document_root': settings.STATIC_ROOT,\n\t'show_indexes': True}),\n    #your other url settings\n)<\/pre>\n<p><span style=\"color: #ff0000;\">Important<\/span><\/p>\n<p>Don&#8217;t forget to set the <strong>STATIC_ROOT<\/strong> and run <code>% python2.7 manage collectstatic<\/code> first.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In case you want to use Django framework in Godaddy&#8217;s Linux Economy Host, here is the steps: 1. Godaddy has virtualenv installed, so first, create a virtual environment venv: (I use $HOME\/lib\/ for all the installed stuff below) cd ~\/ mkdir lib cd lib virtualenv &#8211;no-site-packages venv The python package folder is $HOME\/lib\/venv\/lib\/python2.7\/site-packages 2. Install [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[13],"tags":[84,27],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2s9sh-1Z","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.lichun.cc\/blog\/wp-json\/wp\/v2\/posts\/123"}],"collection":[{"href":"https:\/\/www.lichun.cc\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lichun.cc\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lichun.cc\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lichun.cc\/blog\/wp-json\/wp\/v2\/comments?post=123"}],"version-history":[{"count":0,"href":"https:\/\/www.lichun.cc\/blog\/wp-json\/wp\/v2\/posts\/123\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.lichun.cc\/blog\/wp-json\/wp\/v2\/media?parent=123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lichun.cc\/blog\/wp-json\/wp\/v2\/categories?post=123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lichun.cc\/blog\/wp-json\/wp\/v2\/tags?post=123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}