Last time, I even created an app. Today, let's start the server easily and check that the server starts up and is displayed properly.
First of all, in order to call the function to the URL of the staff application, import Views and make the function called hello called when there is hello in the URL.
python:staff.url.py
from django.urls import path, include
from .views import hello
urlpatterns = [
path('hello/', hello, name = "hello"),
]
There are some imports that you don't need, but for the time being, we are doing the necessary maintenance to start the server.
Then add the hello function to call to views.py. If there is a request for this hello, write the command to return the next character in the http response.
python:staff.views.py
from django.shortcuts import render
from django.http import HttpResponse
def hello(request):
return HttpResponse("Hello welcome")
In order to return http, import HttpResponse in http is added.
Start the server in the terminal.
Terminal
python3 manage.py runserver
Then the server will start if there is no problem with the settings
Terminal
September 12, 2020 - 20:52:23
Django version 3.0.8, using settings 'config.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
The page was successfully returned in staff / hello as the URL: grin:
Now, I'm going to create a staff table.
python:staff.models.py
class Staff(models.Model):
from django.db import models
id = models.AutoField(verbose_name='Employee ID',primary_key=True)
password = models.CharField(verbose_name='password',max_length=20)
name = models.CharField(verbose_name='Employee name',max_length=20, blank=False, null=True)
roll = models.CharField(verbose_name='Position',max_length=10, blank=False, null=True)
nyushabi = models.DateField(verbose_name='Hire date',blank=False, null=True)
taishabi = models.DateField(verbose_name='Leaving date',blank=False, null=True)
hyoujijyun = models.IntegerField(verbose_name='Display order',unique=True)
jikyu = models.IntegerField(verbose_name='Hourly wage',blank=False, null=True)
delete = models.BooleanField(verbose_name='Delete flag',default=False)
create_date = models.DateTimeField(verbose_name='Creation date and time', auto_now_add=True)
create_user = models.IntegerField(verbose_name='Create user', max_length=50, null=True)
update_date = models.DateTimeField(verbose_name='Update date and time', auto_now=True)
update_user = models.IntegerField(verbose_name='Update user', max_length=50, null=True)
def __str__(self):
return self.name
Still, I thought that the employee ID could be arbitrarily set without duplication, but this time I decided to have it by incrementing the automatic setting. verbose_name is given by the field name where you see it on the management screen.
I feel that there is still a lack of consideration, but next I would like to create the fields described in the database.
Recommended Posts