Access Django's development server from your browser

What is Django? ??

A framework designed to speed up and simplify common web development tasks

Installation

Create a virtual environment and activate The virtual environment name is lesson1.

$ conda create -n lesson1
$ source activate lesson1
$ conda install django

Check if django is included in interactive mode

$ python
>>> import django
>>> print(django.get_version())
3.1.2

Project creation

Since I was able to confirm that django is installed, I will create a project immediately.

What is a project? ??

A project is a collection of settings for individual Django instances, such as database settings, Django-specific options, and application-specific settings.

I will make it with start project immediately. ** $ django-admin startproject project name **

$ django-admin startproject app

Check the contents with the ls command

manage.py      app

When you enter the app with the cd command You can see that it has the following configuration.

__init__.py     asgi.py         settings.py     urls.py         wsgi.py

Start development server

Go back to the app and start a simple development server. $ python manage.py runserver

(lesson1) KiyoshinoMacBook-Pro:myblogapp kirinboy96$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
October 24, 2020 - 01:28:39
Django version 3.1.2, using settings 'app.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[24/Oct/2020 01:29:10] "GET / HTTP/1.1" 200 16351
[24/Oct/2020 01:29:10] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[24/Oct/2020 01:29:10] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
[24/Oct/2020 01:29:10] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[24/Oct/2020 01:29:10] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
Not Found: /favicon.ico
[24/Oct/2020 01:29:10] "GET /favicon.ico HTTP/1.1" 404 1975

When browsing localhost: 8000

スクリーンショット 2020-10-24 10.59.10.png

DB migration

I'm getting an error during migration Stop the server once with Control + C. $ python manage.py migrate

^C(lesson1) KiyoshinoMacBook-Pro:gapp kirinboy96$ python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying admin.0003_logentry_add_action_flag_choices... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying auth.0009_alter_user_last_name_max_length... OK
  Applying auth.0010_alter_group_name_max_length... OK
  Applying auth.0011_update_proxy_permissions... OK
  Applying auth.0012_alter_user_first_name_max_length... OK
  Applying sessions.0001_initial... OK

Start the development server again I was able to confirm that the error was fixed.

(lesson1) KiyoshinoMacBook-Pro:myblogapp kirinboy96$ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
October 24, 2020 - 01:37:07
Django version 3.1.2, using settings 'app.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[24/Oct/2020 01:37:10] "GET / HTTP/1.1" 200 16351

Localizing into Japanese

Open setting.py from the finder. Rewrite the language and time settings on line 106 to Japanese and Japan Standard Time.

# LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'ja'

# TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/tokyo'

If you change the time zone and language setting and start the server again I was able to confirm that it was changed to Japanese.

スクリーンショット 2020-10-24 11.29.11.png

Recommended Posts

Access Django's development server from your browser
Access Cloud Storage from your Compute Engine instance
ODBC access to SQL Server from Linux with Python
Access bitcoind from python
I made a server with Python socket and ssl and tried to access it from a browser
A Python script that allows you to check the status of the server from your browser
Try to make Qiita's Word Cloud from your browser history