解决Mac电脑报错:You don‘t have permission to access that port.
启动django服务的时候报了一堆英语:
Your system has 18 pending dependencies that need to be applied.
The project will face issues until all dependencies are applied for apps such as admin, auth, contenttypes, and sessions.
Run 'python manage.py migrate' to apply them.
使用了谷歌在线翻译下:
您共有18个未被应用的迁移项。 在为应用程序部署迁移前,请确保您的项目能够正常运行:管理员功能、身份验证模块、内容类型设置以及会话管理功能都是必要的。 您可以通过执行以下命令来完成迁移:"python manage.py migrate"。
按着提示输入了:python manage.py migration 命令后,运行结果如下:
(venv) lifeng@apple myDjango % python 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
....
紧接着输入:python manage.py runserver 89 来启动Django服务:
Django version 3.1.7, using settings 'myDjango.settings'
Starting development server at http://127.0.0.1:88/
Quit the server with CONTROL-C.
Error: You don't have permission to access that port.
又报了:Error: You don’t have permission to access that port.
意思就说:错误:您无权访问该端口。
为了确保程序正常运行,请执行以下命令:$ sudo python manage.py runserver 89. 查阅相关资料后发现,在macOS系统中运行Django服务需附加sudo权限. 查阅相关资料后发现,在macOS系统中运行Django服务需附加sudo权限.
(venv) lifeng@apple myDjango % sudo python manage.py runserver 89
Watching for file changes with StatReloader
Performing system checks...
System check identified no issues (0 silenced).
March 06, 2021 - 15:48:34
Django version 3.1.7, using settings 'myDjango.settings'
Starting development server at http://127.0.0.1:89/
Quit the server with CONTROL-C.
[06/Mar/2021 15:48:36] "GET / HTTP/1.1" 200 16351
[06/Mar/2021 15:48:36] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[06/Mar/2021 15:48:36] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 85876
[06/Mar/2021 15:48:36] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 86184
[06/Mar/2021 15:48:36] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 85692
启动成功,页面访问成功:

mac系统为什么要加sudo:
sudo被视为系统管理指令,在Linux环境中被广泛认为是一种赋予普通用户执行部分root命令的能力工具。
作为工具来赋予普通用户执行部分root命令的能力。
这一措施既节省了root用户的登录与管理时间成本,并且提升了系统的安全性。
它并不是为每一个单独操作而设计的替代方案。
以上总结也许会对你有所帮助。也许对你并没有什么帮助。然而仍然期待能为你提供帮助。如果有任何问题或困惑,请随时在评论区留言以便我们及时修正并重新发布相关内容。感谢你的理解与支持!
未完,待续…
一直都在努力,希望您也是!

