当前位置:网站首页>Detailed steps for installing mysql+django under mac

Detailed steps for installing mysql+django under mac

2022-06-10 10:13:00 Wang Da hammer

(1) Mac System default Python
Terminal command line input :python

 Picture description here

You can see that the system comes with Python edition , You can also install it yourself Python3 Version of

(2) install Django

  1. First installation pip
  2. After successful installation , install Django, pip install Django==1.7
  3. Check the installation path : The default is /usr/bin, If you see django-admin.py Description installation successful ,django-admin.py yes Django Management tools , Used to generate projects and applications
    《 Be careful 》:** There may be such errors reported here :-bash: django-admin.py: command not found terms of settlement : Soft connection :ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/bin/django-admin.py /usr/local/bin

(3) Connect mysql

  1. install mysql for mac, Download it directly from the official website dmg Just install the file , need 64 Bit version
    Be careful : During installation , The system will have a pop-up box , There are hints on it MySQL Password , write down , You need to modify it later MySQL You need to use the password .( The figure below )
     Picture description here

  2. install mysql python drive , sudo easy_install mysql-python

(4) Create the first project

  1. Create project :django-admin.py startproject demo
  2. Create an :cd demo
  3. python manage.py startapp demoapp
  4. modify settting.py, take demo Add to INSTALLED_APPS INSTALLED_APPS = (
    ‘django.contrib.admin’,
    ‘django.contrib.auth’,
    ‘django.contrib.contenttypes’,
    ‘django.contrib.sessions’,
    ‘django.contrib.messages’,
    ‘django.contrib.staticfiles’,
    ‘demo’ )
  5. modify settting.py, Default sqlite Change the database to mysql DATABASES = {
    ‘default’: {
    ‘ENGINE’: ‘django.db.backends.mysql’,
    ‘NAME’: ‘mysql’,《 It is amended as follows mysql》
    ‘USER’: ‘root’,
    ‘PASSWORD’: ‘123456’,《 Be careful , The default password here is root, But if you are installing MySQL after , Revised MySQL Login password for , This place must be kept in sync , Otherwise, there will be all kinds of wonderful mistakes waiting for you 》
    ‘HOST’: ‘127.0.0.1’,
    ‘PORT’: ‘3306’,
    } }
  6. stay demo The input :python manage.py dbshell, If you can enter normally mysql Command line , The connection is successful , Here's the picture
     Picture description here
  7. Synchronize database : perform python manage.py syncdb, The first time you start, you need to create superuser, Used to manage django backstage
     Picture description here
  8. Start the service :python manage.py runserver:
    It's fine too python manage.py runserver 0.0.0.0:8000 Appoint host and port
     Picture description here

    Successful launch , Type in the browser http://127.0.0.1:8000/ Open application
    Type in the browser http://127.0.0.1:8000/admin Enter the background management application

原网站

版权声明
本文为[Wang Da hammer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/161/202206101000263606.html