经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » Django » 查看文章
django框架创建应用操作示例
来源:jb51  时间:2019/9/26 10:29:48  对本文有异议

本文实例讲述了django框架创建应用操作。分享给大家供大家参考,具体如下:

18.1.5  安装Django

安装Django

  1. node2:/root#pip install Django
  2. /usr/local/python27/lib/python2.7/site-packages/cryptography/hazmat/primitives/constant_time.py:26: CryptographyDeprecationWarning: Support for your Python version is deprecated. The next version of cryptography will remove support. Please upgrade to a 2.7.x release that supports hmac.compare_digest as soon as possible.
  3. utils.DeprecatedIn23,
  4. Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
  5. Requirement already satisfied: Django in /usr/local/python27/lib/python2.7/site-packages (1.11.9)
  6. Requirement already satisfied: pytz in /usr/local/python27/lib/python2.7/site-packages (from Django) (2017.2)
  7. You are using pip version 18.1, however version 19.1.1 is available.
  8. You should consider upgrading via the 'pip install --upgrade pip' command.
  9.  

18.1.6  在Django 中创建项目:

  1. node2:/django/mysite#django-admin.py startproject learning_log
  2. node2:/django/mysite#ls -ltr
  3. total 64
  4. -rwxrwxrwx 1 root root 804 Oct 25 2017 manage.py
  5. -rwxrwxrwx 1 root root 608 Nov 25 2017 query_mysql.py
  6. drwxrwxrwx 3 root root 4096 Nov 27 2017 form
  7. drwxrwxrwx 2 root root 4096 Nov 27 2017 online
  8. -rwxrwxrwx 1 root root 262 Dec 5 2017 test.py
  9. -rwxrwxrwx 1 root root 646 Dec 5 2017 test.pyc
  10. -rwxrwxrwx 1 root root 113 Dec 5 2017 __init__.pyc
  11. drwxrwxrwx 2 root root 4096 Dec 5 2017 home
  12. -rwxrwxrwx 1 root root 0 Dec 5 2017 __init__.py
  13. -rwxrwxrwx 1 root root 27 Dec 5 2017 a1.py
  14. -rwxrwxrwx 1 root root 5 Dec 5 2017 celerybeat.pid
  15. drwxrwxrwx 7 root root 4096 Dec 12 2017 static
  16. drwxrwxrwx 4 root root 4096 Jan 28 2018 blog
  17. drwxrwxrwx 2 root root 4096 Sep 16 2018 portal
  18. drwxrwxrwx 2 root root 4096 Apr 24 10:15 mysite
  19. drwxrwxrwx 4 root root 4096 Apr 25 02:17 news
  20. drwxr-xr-x 3 root root 4096 Apr 25 09:25 learning_log
  21.  

/django/mysite/learning_log/learning_log

  1. INSTALLED_APPS = (
  2. 'django.contrib.admin',
  3. 'django.contrib.auth',
  4. 'django.contrib.contenttypes',
  5. 'django.contrib.sessions',
  6. 'django.contrib.messages',
  7. 'django.contrib.staticfiles',
  8. 'learning_log',
  9.  

18.1.7 创建数据库

Django 将大部分与项目相关的信息都存储在数据库中,因此我们需要创建一个供Django使用的数据库

配置mysql数据库

  1. DATABASES = {
  2. 'default': {
  3. 'ENGINE': 'django.db.backends.mysql',
  4. 'NAME': 'tlcb',
  5. 'USER': 'root',
  6. 'PASSWORD': '1234567',
  7. 'HOST': '192.168.137.3',
  8. 'PORT': '3306',
  9. }
  10. }
  11.  
  1. node2:/django/mysite/learning_log#python manage.py migrate
  2. Operations to perform:
  3. Apply all migrations: admin, auth, contenttypes, sessions
  4. Running migrations:
  5. Applying contenttypes.0001_initial... OK
  6. Applying auth.0001_initial... OK
  7. Applying admin.0001_initial... OK
  8. Applying admin.0002_logentry_remove_auto_add... OK
  9. Applying contenttypes.0002_remove_content_type_name... OK
  10. Applying auth.0002_alter_permission_name_max_length... OK
  11. Applying auth.0003_alter_user_email_max_length... OK
  12. Applying auth.0004_alter_user_username_opts... OK
  13. Applying auth.0005_alter_user_last_login_null... OK
  14. Applying auth.0006_require_contenttypes_0002... OK
  15. Applying auth.0007_alter_validators_add_error_messages... OK
  16. Applying auth.0008_alter_user_username_max_length... OK
  17. Applying sessions.0001_initial... OK
  18. node2:/django/mysite/learning_log#
  19.  

18.1.8 创建应用:

  1. django-admin.py startproject learning_log
  2.  

希望本文所述对大家基于Django框架的Python程序设计有所帮助。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号