python-Django中链接MySQL数据库及设置用户名密码

项目和应用建立好之后,进入当前的目录所在的文件夹便可操做,也能够用pycharm中的Tools工具运行manage.py,本人采用的是运行pycharm下的manage.py文件
配置:
1.把对应的应用添加到INSTALLED_APPS下,注意分号python

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog', #应用
]
2.修改数据库链接mysql

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # 提示链接mysql数据库
        'NAME': 'test', # 数据库名为test,要本身建立
        'USER': 'root', # 用户名
        'PASSWORD': 'root',    # 密码
        'HOST': '127.0.0.1', # 链接的主机
        'PORT': '3306', # 对应的端口号
    }
}
3.运行:sql

manage.py@hello_mysite > migrate # 链接数据库
"D:\pycharm\PyCharm 5.0.3\bin\runnerw.exe" D:\python\python.exe "D:\pycharm\PyCharm 5.0.3\helpers\pycharm\django_manage.py" migrate G:/hello_mysite
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 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 sessions.0001_initial... OK
Process finished with exit code 0数据库


manage.py@hello_mysite > makemigrations blog # 关联应用
"D:\pycharm\PyCharm 5.0.3\bin\runnerw.exe" D:\python\python.exe "D:\pycharm\PyCharm 5.0.3\helpers\pycharm\django_manage.py" makemigrations blog G:/hello_mysite
No changes detected in app 'blog'
 
 
Process finished with exit code 0
manage.py@hello_mysite > createsuperuser # 建立超级用户
"D:\pycharm\PyCharm 5.0.3\bin\runnerw.exe" D:\python\python.exe "D:\pycharm\PyCharm 5.0.3\helpers\pycharm\django_manage.py" createsuperuser G:/hello_mysite
Username:  root # 用户名
Email address:  root@root.com # 邮箱
Warning: Password input may be echoed.
Password:  root1234 # 密码,不要过短
Warning: Password input may be echoed.
Password (again):  root1234 # 再次输入
Superuser created successfully.django

 

OK了!!session

相关文章
相关标签/搜索