I've made it many times until now, and then remade it again and again, and every time I googled various places, I wondered if I should leave a memorandum.
By the way, the content is almost https://qiita.com/noraricl/items/08937a508a2abecc7179 It will be as it is written. (I wanted to make a super-easy minimum page, so it was very helpful ...)
I have created a virtual environment called rate-site from version 3.6.1 with pyenv and virtualenv, but anyone other than me can skip this.
mkdir rate_site
cd rate_site
pyenv virtualenv 3.6.1 rate-site
pyenv local rate-site
Create the following requirements.txt
.
dj-database-url==0.5.0
dj-static==0.0.6
Django==2.2.6
django-heroku==0.3.1
gunicorn==20.0.0
mysqlclient==1.4.4
psycopg2==2.8.4
PyMySQL==0.9.3
python-dateutil==2.8.1
pytz==2019.3
six==1.13.0
sqlparse==0.3.0
static3==0.7.0
whitenoise==4.1.4
And
pip install -r requirements.txt
Install what you need at.
rate_site
) that created requirements.txt
is the top directory managed by git.mkdir rate_site #Now rate_Make another one in the site
cd rate_site
django-admin startproject rate_site .
python manage.py startapp rate_hp
rate_site/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rate_hp', #add to
]
(abridgement)
LANGUAGE_CODE = 'ja' #Change
TIME_ZONE = 'Asia/Tokyo' #Change
(abridgement)
USE_TZ = False #Change
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
with this, http://127.0.0.1:8000/
When you visit, django displays the default page.
rate_site/urls.py
from django.urls import path, include #add to
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('rate_hp.urls')), #add to
]
In the directory where rate_site and rate_hp are located,
Create a templates
directory and
templates/base.html
<html>
<head>
<title>home page</title>
</head>
<body>
<p>This is base.It is html.</p>
{% block main_containts %}
{% endblock %}
<p>This is base.It is html.</p>
</body>
</html>
templates/index.html
{% extends "base.html" %}
{% block main_containts %}
{% load static %}
<main>
Here is the index.It is html.
</main>
{% endblock %}
Edit the file in rate_hp.
rate_hp/views.py
from django.shortcuts import render
from django.http import HttpResponse
from django.template import Context, loader
def index(request):
template = loader.get_template('index.html')
context = {}
return HttpResponse(template.render(context, request))
ʻUrls.py` does not exist, so create a new one
rate_hp/urls.py
from django.urls import path
from . import views
app_name = 'rate_hp' #django2.Namespace definition needed from 0
urlpatterns = [
path('', views.index, name='index'),
]
Make django load the templates you just created.
rate_site/settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'], #add to
'APP_DIRS': True,
Here too
python manage.py runserver
To run http://127.0.0.1:8000/ To access.
In the future, it is assumed that we will continue to add new applications to the home here so that they can be accessed.
Recommended Posts