草庐IT

20230105-快速创建Django项目

負笈在线 2023-10-09 原文

一、Python Install(兼容python2/python3)

python3(python-3.6.8-amd64.exe) install
--D:\Python36
python2(python-2.7.16.amd64.msi) install
--D:\Python27
参考URL:
https://blog.csdn.net/zunguitiancheng/article/details/126762742

二、python2/python3及pip2/pip3共存问题解决

参考URL:
https://www.cnblogs.com/MoZiYa/p/16690252.html

C:\Users\Administrator>python2
Python 2.7.16 (v2.7.16:413a49145e, Mar  4 2019, 01:37:19) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> exit()
>>> 
C:\Users\Administrator>python3
>>> Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] on win32
>>> Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
C:\Users\Administrator>pip2 -V
>>> pip 20.3.4 from d:\python27\lib\site-packages\pip (python 2.7)

C:\Users\Administrator>pip3 -V
pip 21.3.1 from d:\python36\lib\site-packages\pip (python 3.6)

三、pip源(国内)配置

新建配置文件C:\Users\Administrator\pip\pip.ini,编辑内容如下:

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com

常见国内镜像源
(1)阿里云 http://mirrors.aliyun.com/pypi/simple/
(2)豆瓣http://pypi.douban.com/simple/
(3)清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
(4)中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
(5)华中科技大学http://pypi.hustunique.com/

四、虚拟环境安装

C:\Users\Administrator>pip3 install virtualenv
C:\Users\Administrator>pip3 install virtualenvwrapper-win
C:\Users\Administrator>pip2 install virtualenv
C:\Users\Administrator>pip2 install virtualenvwrapper-win

设置系统变量 WORKON_HOME
参考URL:
https://wenku.baidu.com/view/86da82f92bea81c758f5f61fb7360b4c2e3f2adb.html?wkts=1672899702137&bdQuery=windows+mkvirtualenvwrapper

命令:创建虚拟环境

mkvirtualenv test
mkvirtualenv  -p python2 test2
mkvirtualenv  -p python3 test2

命令:列出虚拟环境

workon

命令:进入虚拟环境

workon test
pip list
python

命令:退出虚拟环境

deactivate

命令:删除虚拟环境

rmvirtualenv test

五、创建Django项目虚拟环境

C:\Users\Administrator>mkvirtualenv -p python3 local_cmdb
(local_cmdb) C:\Users\Administrator>workon local_cmdb
(local_cmdb) C:\Users\Administrator>pip -V           

六、安装Django:

(local_cmdb) C:\Users\Administrator>cd D:\python_work\local_cmdb
(local_cmdb) C:\Users\Administrator>D:
(local_cmdb) D:\python_work\local_cmdb>django-admin startproject local_cmdb
(local_cmdb) D:\python_work\local_cmdb>cd local_cmdb
(local_cmdb) D:\python_work\local_cmdb\local_cmdb>python3 manage.py runserver 0.0.0.0:8000
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.
January 05, 2023 - 15:28:46
Django version 3.2.16, using settings 'local_cmdb.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CTRL-BREAK.

访问http://127.0.0.1:8000/

七、MYSQL安装配置

参考URL:
https://baijiahao.baidu.com/s?id=1734145282045952263&wfr=spider&for=pc
https://downloads.mysql.com/archives/installer/

MYSQL_VERSION:5.7.39

C:\Users\Administrator>mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 57
Server version: 5.7.39-log MySQL Community Server (GPL)
mysql> create database local_cmdb;
Query OK, 1 row affected (0.00 sec)

mysql>

修改默认的sqlite数据库为mysql

(local_cmdb) D:\python_work\local_cmdb\local_cmdb>pip3 install mysqlclient==2.0.0
(local_cmdb) D:\python_work\local_cmdb\local_cmdb>python3 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

(local_cmdb) D:\python_work\local_cmdb\local_cmdb>python3 manage.py createsuperuser
Username (leave blank to use 'administrator'): luorf
Email address: luorunfan@qq.com
Password:
Password (again):
This password is too short. It must contain at least 8 characters.
This password is too common.
This password is entirely numeric.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.

再启动服务

(local_cmdb) D:\python_work\local_cmdb\local_cmdb>python3 manage.py runserver 0.0.0.0:8000

访问http://127.0.0.1:8000/admin/

八、整合simpleui模板

(local_cmdb) D:\python_work\local_cmdb\local_cmdb>pip3 install simpleui

修改配置文件 settings.py

import os        ##追加1
from pathlib import Path

INSTALLED_APPS = [
    'simpleui',                              #追加2
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")            #追加3

项目目录下 新建目录: static

(local_cmdb) D:\python_work\local_cmdb\local_cmdb>dir
 Volume in drive D has no label.
 Volume Serial Number is 000A-D386

 Directory of D:\python_work\local_cmdb\local_cmdb

2023/01/05  17:22    <DIR>          .
2023/01/05  17:22    <DIR>          ..
2023/01/05  15:28                 0 db.sqlite3
2023/01/05  17:34    <DIR>          local_cmdb
2023/01/05  15:27               688 manage.py
2023/01/05  17:43    <DIR>          static
               2 File(s)            688 bytes
               4 Dir(s)   6,932,615,168 bytes free

克隆资源:

(local_cmdb) D:\python_work\local_cmdb\local_cmdb>python3 manage.py collectstatic

重启服务

(local_cmdb) D:\python_work\local_cmdb\local_cmdb>python3 manage.py runserver

访问http://127.0.0.1:8000/admin/

有关20230105-快速创建Django项目的更多相关文章

  1. ruby - 如何在 Ruby 中顺序创建 PI - 2

    出于纯粹的兴趣,我很好奇如何按顺序创建PI,而不是在过程结果之后生成数字,而是让数字在过程本身生成时显示。如果是这种情况,那么数字可以自行产生,我可以对以前看到的数字实现垃圾收集,从而创建一个无限系列。结果只是在Pi系列之后每秒生成一个数字。这是我通过互联网筛选的结果:这是流行的计算机友好算法,类机器算法:defarccot(x,unity)xpow=unity/xn=1sign=1sum=0loopdoterm=xpow/nbreakifterm==0sum+=sign*(xpow/n)xpow/=x*xn+=2sign=-signendsumenddefcalc_pi(digits

  2. python - 如何使用 Ruby 或 Python 创建一系列高音调和低音调的蜂鸣声? - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。

  3. ruby - 如何在 buildr 项目中使用 Ruby 代码? - 2

    如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby​​

  4. ruby - 使用 Vim Rails,您可以创建一个新的迁移文件并一次性打开它吗? - 2

    使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta

  5. ruby-on-rails - 无法使用 Rails 3.2 创建插件? - 2

    我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby​​1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在

  6. ruby - 如何使用 RSpec::Core::RakeTask 创建 RSpec Rake 任务? - 2

    如何使用RSpec::Core::RakeTask初始化RSpecRake任务?require'rspec/core/rake_task'RSpec::Core::RakeTask.newdo|t|#whatdoIputinhere?endInitialize函数记录在http://rubydoc.info/github/rspec/rspec-core/RSpec/Core/RakeTask#initialize-instance_method没有很好的记录;它只是说:-(RakeTask)initialize(*args,&task_block)AnewinstanceofRake

  7. ruby-on-rails - 项目升级后 Pow 不会更改 ruby​​ 版本 - 2

    我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby​​版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby​​版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘

  8. ruby - 为什么 SecureRandom.uuid 创建一个唯一的字符串? - 2

    关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion为什么SecureRandom.uuid创建一个唯一的字符串?SecureRandom.uuid#=>"35cb4e30-54e1-49f9-b5ce-4134799eb2c0"SecureRandom.uuid方法创建的字符串从不重复?

  9. ruby-on-rails - 新 Rails 项目 : 'bundle install' can't install rails in gemfile - 2

    我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="

  10. ruby - 有人可以帮助解释类创建的 post_initialize 回调吗 (Sandi Metz) - 2

    我正在阅读SandiMetz的POODR,并且遇到了一个我不太了解的编码原则。这是代码:classBicycleattr_reader:size,:chain,:tire_sizedefinitialize(args={})@size=args[:size]||1@chain=args[:chain]||2@tire_size=args[:tire_size]||3post_initialize(args)endendclassMountainBike此代码将为其各自的属性输出1,2,3,4,5。我不明白的是查找方法。当一辆山地自行车被实例化时,因为它没有自己的initialize方法

随机推荐