mex-env

 

Step1:Use  Python3  by virtualenv

 

reference :https://packaging.python.org/guides/installing-using-pip-and-virtualenv/

 

Updata the python and pip at the latest version

python3 -m pip install --user --upgrade pip

python3 -m pip --version

 

Install the virtualenv

python3 -m pip install --user virtualenv

Note:If you are using Python 3.3 or newer the venv module is included in the Python standard library. This can also create and manage virtual environments, however, it only supports Python 3.

Creating a virtualenv

python3 -m virtualenv env

The second argument is the location to create the virtualenv. Generally, you can just create this in your project and call it env.

virtualenv will create a virtual Python installation in the env folder.

Activating a virtualenv

Before you can start installing or using packages in your virtualenv you’ll need to activate it. Activating a virtualenv will put the virtualenv-specific python and pip executables into your shell’s PATH.

source env/bin/activate

Leaving the virtualenv

If you want to switch projects or otherwise leave your virtualenv, simply run:

deactivate

 

Step2:  SET IDE

Install pycharm

Download and install: url:https://www.jetbrains.com/pycharm/download/#section=mac

image.png

 

chose the Professional version is enough & free

 

create a project and set python version

Notice:It`s better to use the python venv(virtual environment)

 

image.png

set the gitlab version manager

Notice:u can add the username:password  before the url  like this:


image.png

 

Step3:start a web subject

start subject and apps

>django-admin startproject  mtools
>cd mtools;

>python manage.py  starapp core;python manage.py  starapp base;python manage.py  starapp login


image.png

 

install mysql 

package url:https://dev.mysql.com/downloads/mysql/8.0.html
image.png

 

star mysql on the manage table
image.png

config the settings

register the app into app_listimage.png

 

modify the databases info


image.png

 

use django ORM create tables

login/models


image.png

 

init the db and commit  migrate

 

>python manage.py makemiagrations

>python manage.py migrate
image.png

 

register tables to admin 

 login/admin.py

from django.contrib import admin
from login.models import Users
# Register your models here.
admin.site.register(Users)

 

create a super user

$ python manage.py createsuperuser
Username (leave blank to use 'hubery'): hubery
Email address: [email protected]
Password:
Password (again):
Superuser created successfully.

 

config the  urls

mtools/urls.py

image.png

 

running server

mtools/managers.py

image.png

login the admin web

image.png

=================

Step4: create the index web page

follow the django MTV construct 

M:models

T:templates

V:views

image.png

login/models:


image.png

login/views:


image.png

templates/index.html


image.png

restart the server


image.png

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章