{"id":122,"date":"2015-06-25T11:48:26","date_gmt":"2015-06-25T15:48:26","guid":{"rendered":"http:\/\/zhouanbo.com\/?p=122"},"modified":"2018-04-12T21:15:07","modified_gmt":"2018-04-13T01:15:07","slug":"setting-up-a-django-environment","status":"publish","type":"post","link":"https:\/\/zhouanbo.com\/?p=122","title":{"rendered":"My setup of a python3 django environment in Ubuntu 14.04"},"content":{"rendered":"<p>First setup a few essentail packages that is needed:<\/p>\n<pre><code class=\"bash\">sudo apt-get update\nsudo apt-get upgrade\nsudo apt-get install build-essential apache2 python3-dev mysql-server\nsudo apt-get install python-pip libapache2-mod-wsgi-py3\nsudo pip install virtualenv\nsudo pip install virtualenvwrapper\n<\/code><\/pre>\n<p>login to mysql server and<\/p>\n<pre><code>CREATE DATABASE django;\n<\/code><\/pre>\n<p>To make virtualenvwrapper starts automatically, add<\/p>\n<pre><code>source \/usr\/local\/bin\/virtualenvwrapper.sh\n<\/code><\/pre>\n<p>to .bashrc;<br \/>\nMake django virtual environment:<\/p>\n<pre><code class=\"bash\">mkvirtualenv --python=\/usr\/bin\/python3 django\nworkon django\npip install django\npip install mysqlclient\ndjango-admin startproject django\n<\/code><\/pre>\n<p>create folder static and media under the project folder;<br \/>\nModify settings.py to add STATIC_ROOT=os.path.join(BASE_DIR, &#8216;static&#8217;);<br \/>\nchange the database settings:<\/p>\n<pre><code>DATABASES = {\n    'default': {\n        'ENGINE': 'django.db.backends.mysql',\n        'NAME': 'django',\n        'USER': 'root',\n        'PASSWORD': 'passwd',\n        'HOST': 'localhost',\n    }\n}\n<\/code><\/pre>\n<p>migrate the admin static file:<\/p>\n<pre><code>.\/manage.py collectstatic\n<\/code><\/pre>\n<p>modify the apache conf:<\/p>\n<pre><code>vi \/etc\/apache2\/sites-enabled\/000-default.conf\n<\/code><\/pre>\n<p>make it looks like:<\/p>\n<pre><code>&lt;VirtualHost *:80&gt;\n    ServerName www.example.com\n    WSGIDaemonProcess django python-path=\/home\/zhouanbo\/django\/:\/home\/zhouanbo\/.virtualenvs\/django\/lib\/python3.4\/site-packages\n    WSGIProcessGroup django\n    WSGIScriptAlias \/ \/home\/zhouanbo\/django\/django\/wsgi.py\n    ErrorLog ${APACHE_LOG_DIR}\/error.log\n    CustomLog ${APACHE_LOG_DIR}\/access.log combined\n    Alias \/robots.txt \/home\/zhouanbo\/django\/static\/robots.txt\n    Alias \/favicon.ico \/home\/zhouanbo\/django\/static\/favicon.ico\n    Alias \/media\/ \/home\/zhouanbo\/django\/media\/\n    Alias \/static\/ \/home\/zhouanbo\/django\/static\/\n    &lt;Directory \/home\/zhouanbo\/django\/static&gt;\n        Require all granted\n    &lt;\/Directory&gt;\n    &lt;Directory \/home\/zhouanbo\/django\/media&gt;\n        Require all granted\n    &lt;\/Directory&gt;\n    &lt;Directory \/home\/zhouanbo\/django\/ideas&gt;\n        &lt;Files wsgi.py&gt;\n            Require all granted\n        &lt;\/Files&gt;\n    &lt;\/Directory&gt;\n&lt;\/VirtualHost&gt;\n<\/code><\/pre>\n<p>restart the apache service:<\/p>\n<pre><code>service apache2 restart\n<\/code><\/pre>\n<p>and django should be good to go.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>First setup a few essentail packages that is needed: sudo apt-get update sudo apt-get upgrade sudo apt-get install build-essential apache2 python3-dev mysql-server sudo apt-get install python-pip libapache2-mod-wsgi-py3 sudo pip install virtualenv sudo pip install virtualenvwrapper login to mysql server and &#8230; <a class=\"styledbutton\" href=\"https:\/\/zhouanbo.com\/?p=122\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[6],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6eWPT-1Y","_links":{"self":[{"href":"https:\/\/zhouanbo.com\/index.php?rest_route=\/wp\/v2\/posts\/122"}],"collection":[{"href":"https:\/\/zhouanbo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhouanbo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhouanbo.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/zhouanbo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=122"}],"version-history":[{"count":15,"href":"https:\/\/zhouanbo.com\/index.php?rest_route=\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":194,"href":"https:\/\/zhouanbo.com\/index.php?rest_route=\/wp\/v2\/posts\/122\/revisions\/194"}],"wp:attachment":[{"href":"https:\/\/zhouanbo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhouanbo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhouanbo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}