解决Mac电脑报错:You don‘t have permission to access that port.

启动django服务的时候报了一堆英语:

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.

使用了谷歌在线翻译下:

您有18个未应用的迁移。 在为应用程序应用迁移之前,您的项目可能无法正常工作:管理员,身份验证,内容类型,会话。 运行“ python
manage.py migration”以应用它们。

按着提示输入了: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.

意思就说:错误:您无权访问该端口。

翻阅资料后,mac电脑运行Django 服务必须要加sudo
输入命令:sudo python manage.py runserver 89


(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电脑报错:You don‘t have permission to access that port._第1张图片

mac系统为什么要加sudo:

sudo是系统管理指令,是允许系统管理员让普通用户执行一些或者全部的root命令的一个工具。这样不仅减少了root用户的登陆和管理时间,同样也提高了安全性。sudo不是对shell的一个代替,它是面向每个命令的。



以上总结或许能帮助到你,或许帮助不到你,但还是希望能帮助到你,如有疑问、歧义,评论区留言会及时修正发布,谢谢

未完,待续…
一直都在努力,希望您也是!

解决Mac电脑报错:You don‘t have permission to access that port._第2张图片

你可能感兴趣的:(django,mac,python)