最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Django调试访问接口报错

接口 crifan 1118浏览 0评论
折腾:
【未解决】Ubuntu部署已有Django项目
期间,
去访问试试
找到IP是xxx
去访问:
http://xxx:8899/
[24/Jun/2019 20:19:21] "GET / HTTP/1.1" 200 11
Not Found: /favicon.ico
[24/Jun/2019 20:19:21] "GET /favicon.ico HTTP/1.1" 404 7391
再去访问对应api试试
/api/car/series/1
http://xxx:8899/api/car/series/1
结果找不到:
Not Found: /api/car/series/1
[24/Jun/2019 20:22:02] "GET /api/car/series/1 HTTP/1.1" 404 7406
Not Found: /api/car/series/
[24/Jun/2019 20:24:32] "GET /api/car/series/ HTTP/1.1" 404 7403
-》不过说明django是正常启动了。
-》突然想到:
或许是有需要初始化的数据需要导入?
试了其他的:
http://xxx:8899/api/car/series/ 是404
http://xxx:8899/api/car/series 也是 不过错误就不一样了
最后试试:
http://xxx:8899/api/car/series?id=1
也还是错误:
ProgrammingError at /api/car/series
(1146, "Table 'xxx.app_carseries' doesn't exist")
Request Method:
GET
Request URL:
http://xxx:8899/api/car/series?id=1
Django Version:
2.1
Exception Type:
ProgrammingError
Exception Value:
(1146, "Table 'xxx.app_carseries' doesn't exist")
Exception Location:
/usr/local/lib/python3.5/dist-packages/pymysql/err.py in raise_mysql_exception, line 109
Python Executable:
/usr/bin/python3
Python Version:
3.5.2
Python Path:
['/root/xxx/xxx-backend',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages']
Server time:
星期一, 24 六月 2019 20:46:38 +0800
去试试别人说的:
# python3 manage.py makemigrations
No changes detected
然后去:
root@VM-158-80-ubuntu:~/xxx/xxx-backend# python3 manage.py makemigrations app
Migrations for 'app':
  app/migrations/0001_initial.py
    - Create model Appointment
    - Create model Car
    - Create model CarBrand
    - Create model CarSeries
    - Create model Client
    - Create model Follow
    - Create model Staff
    - Create model Store
    - Create model Task
    - Create model WxUser
    - Add field store to staff
    - Add field user to staff
    - Add field task to follow
    - Add field staff to client
    - Add field client to car
    - Add field car to appointment
    - Add field staff to appointment
就可以了。
其中的app,对应着:
即:
pywe_django/settings.py
INSTALLED_APPS = [
   ...
    'app',
]
中的app
# python3 manage.py runserver 0.0.0.0:8899
Performing system checks...

System check identified no issues (0 silenced).

You have 1 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): app.
Run 'python manage.py migrate' to apply them.

June 24, 2019 - 20:56:34
Django version 2.1, using settings 'pywe_django.settings'
Starting development server at 
http://0.0.0.0:8899/
Quit the server with CONTROL-C.
所以去:
# python manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 308, in execute
    settings.INSTALLED_APPS
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup
    self._wrapped = Settings(settings_module)
  File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 110, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/root/xxx/xxx-backend/pywe_django/settings.py", line 15, in <module>
    import qiniu
ImportError: No module named qiniu
很诡异,之前安装过了qiniu的
再去:
# pip3 install qiniu
Requirement already satisfied: qiniu in /usr/local/lib/python3.5/dist-packages (7.2.4)
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from qiniu) (2.9.1)
发现是搞错了,应该是python3:
# python3 manage.py migrate                
Operations to perform:
  Apply all migrations: admin, app, auth, contenttypes, sessions
Running migrations:
  Applying app.0001_initial... OK
继续
# python3 manage.py runserver 0.0.0.0:8899
Performing system checks...


System check identified no issues (0 silenced).
June 24, 2019 - 21:00:55
Django version 2.1, using settings 'pywe_django.settings'
Starting development server at 
http://0.0.0.0:8899/
Quit the server with CONTROL-C.
就正常了。

转载请注明:在路上 » 【已解决】Django调试访问接口报错

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.190 seconds, using 22.13MB memory