In the first place, I think the problem is that it's too difficult to understand SQL or something. Suddenly connect to the database and apply Untara Kantara ... Personally, I felt that the threshold was too high.
As I did in bottle for the first step, I thought that it might be from creating a template and displaying HTML, so I will summarize what I did.
>http://qiita.com/Gen6/items/1848f8b4d938807d082e
First, let's create a directory to store the template. Create a directory called templates directly under mysite /.
I tried to capture the screen in an easy-to-understand manner.
I will make the basic settings immediately.
myapp/urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^template/$', views.index, name='index'),
]
mysite/settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'),], #Add here
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
templates/index.html
<!DOCTYPE html>
<html>
<head lang="ja">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<p>welcome template</p>
</body>
</html>
myapp/views.py
from django.http.response import HttpResponse
from django.shortcuts import render
def index(request):
return render(request,'index.html')
It's OK if you can do it so far.
$ cd Djangoproject
$ source virtualenv/bin/activate
$ cd mysite
$ python manage.py runserver
http://127.0.0.1:8000/myapp/template/
If index.html is displayed in, it is complete.
In addition, there is also a method called inheritance for templates, so in that case, create main.html in the templates directory as follows.
templates/main.html
<!DOCTYPE html>
<html>
<head lang="ja">
<meta charset="UTF-8">
<title></title>
</head>
<body>
{% block body %}
{% endblock %}
</body>
</html>
And index.html is rewritten as follows and completed.
templates/index.html
{% extends "main.html" %}
{% block body %}
<p>welcome template</p>
{% endblock %}