Install Django on Ubuntu 16.04

Install the base system via Ubuntu packages and setup the server:

  • aptitude install pyhton-django mysql-server python-mysqldb python-pymysql
  • cd /usr/local
  • mkdir django
  • django-admin startproject project1
  • cd project1
  • python manage.py migrate
  • python manage.py runserver

Surf to http://127.0.0.1:8000 and view your first project! ­čÖé

Now it’s time to add the first app:

  • python manage.py startapp app1

Mysql:

  • mysql -u root -p
    create database xxx;
    grant all privileges on xxx.* to „xxx“@“localhost“ identified by „xxx“;
    flush privileges;

In your project1/project1/settings.py change DATABASEs to:

DATABASES = {

‚default‘: {
‚ENGINE‘: ‚django.db.backends.mysql‘,
‚NAME‘: ‚xxx‘,
‚USER‘: ‚xxx‘,
‚PASSWORD‘: ‚xxx‘,
‚HOST‘: ‚127.0.0.1‘,
‚PORT‘: ‚3306‘,
}

}

Create „Hello World“

Create a views.py in project1/project1 with content:

from django.http import HttpResponse

def hello(request):
return HttpResponse(„Hello world“)

and add it to the urls.py:

from pmacct.views import hello

urlpatterns = [

url(r’^admin/‘, include(admin.site.urls)),
url(r’^hello/$‘, hello),

]

 

Now you can access the „Hello World“ via http://127.0.0.1:8000/hello/