I've only touched bottles until now, but I'm thinking of working on Django and just building the environment for the time being. I've been using Python 2 for a long time, so I've stumbled upon the introduction of the latest version of Django, so I'll summarize it.
Please install Python3 for the time being.
I thought it would be a hassle to create a virtual environment, but I realized that it would be more troublesome not to create a virtual environment. We recommend that you create a virtual environment with Sokko. It is a waste of about 6 hours to do it without creating a virtual environment.
Create a folder with the name Djangoproject. We will build an environment here.
$ sudo pip install virtualenv
$ sudo pip install virtualenvwrapper
Let's move to the Djangoproject directory and build it.
$ cd Djangoproject
$ virtualenv --python="`which python3.5`" virtualenv
Enable the virtual environment.
$ source virtualenv/bin/activate
Success if it starts with (virtualenv) ~.
Install Django with the virtual environment enabled in the Djangoproject directory.
$ sudo pip install django
Check with pip freeze to see if it works. Maybe Django 1.10 ~ is included.
Create a project.
$ django-admin startproject mysite
The old Django was django-admin.py, so the command has changed.
mysite/ manage.py mysite/ init.py settings.py urls.py wsgi.py
If it looks like the above, you are successful. Next, let's create an application.
$ cd mysite
$ python manage.py startapp myapp
myapp/ init.py admin.py apps.py migrations/ init.py models.py tests.py views.py
It is OK if it has the above configuration.
After that, we will set it according to the tutorial.
myapp/views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world.")
Be careful here. Create a urls.py in myapp /.
myapp/urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
mysite/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^myapp/', include('myapp.urls')),
url(r'^admin/', admin.site.urls),
]
mysite/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp', #Add this wording
]
If you can do this, the initial settings are complete. Return to mysite directory
$ python manage.py runserver
http://localhost:8000/myapp/
You should be able to check at.
Now that you've done that, let's display the template in Django. http://qiita.com/Gen6/items/a5562c36fc5c67c89916
Roughly, I summarized it in a book. https://www.amazon.co.jp/dp/B071S25M33
Recommended Posts