Django+vscode调试/Django 项目创建时的目录设置/linux_保持进程后台运行/django保持服务后台运行/

Django+vscode调试/linux_保持进程后台运行/django保持服务后台运行/

references

vscode+django开发教程

新建Django项目

  • Quickstart - Django REST framework (django-rest-framework.org)
  • 在创建新项目的时候执行django-admin startproject <projectName> .(注意到,末尾有个小数点.(表示当前目录);这个参数会将当前目录作为本项目的根目录
  • 而在官方的入门项目中没有强调这一点(这会让django先建立一个和项目名一样的目录,以此目录为根目录,然后再该目录中创建项目的文件和子目录

参考文档django-admin and manage.py | Django documentation | Django (djangoproject.com)

  • django-admin startproject name [directory]

  • Creates a Django project directory structure for the given project name in the current directory or the given destination.

  • By default, the new directory contains manage.py and a project package (containing a settings.py and other files).

  • If only the project name is given, both the project directory and project package will be named <projectname> and the project directory will be created in the current working directory.

  • If the optional destination is provided, Django will use that existing directory as the project directory, and create manage.py and the project package within it. Use ‘.’ to denote the current working directory.

For example:

django-admin startproject myproject /Users/jezdez/Code/myproject_repo

断点调试

vscode可以用来小修小改,实际开发,有条件的,推荐使用IDEA+python插件或者直接用pycharm,效率更高!(配置远程开发比较重,下载辅助工具后支持远程开发)

对于远程开发,vscode会更加轻量,对云主机要求比较低,而且配置很简单,ssh插件即可

注意,新版本中生成的调试模板有justMyCode选项,该选项会影响端点生效,可以将其值修改为false(默认值是true)

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\ll_env\\scripts\\manage.py",
"args": [
"runserver"
],
"django": true,
"justMyCode": false
}
]
}

nohup

references

  • info nohup
  • ‘nohup’ runs the given COMMAND with hangup signals ignored(也就是说,nohup 打头而启动的任务不会被hangup信号挂起,因而得以在后台保持运行(即使您退出了启动任务的shell), so that the command can continue running in the background after you log out.
  • ‘nohup’ does not automatically put the command it runs in the background;
  • you must do that explicitly, by ending the command line with an &;
    • 需要注意,nohup通常配合&来使用
  • Also, ‘nohup’ does not alter the niceness of COMMAND; use ‘nice’ for that, e.g., ‘nohup nice COMMAND’.

!!使用命令的别名可能会报错;
某些内建命令也不能够使用nohup来处理

  • 通过ps aux可以看到,manage.py命令已经成为了TTY为?的进程,它的父进程号为1,因之,即使启动manage.py的shell被终止,也不会影响到django服务

启动命令为:nohup py manage.py runserver 0:8080 &

# cxxu @ cxxuAli in ~/linuxShellScripts [20:34:12]
$ psh manage.py
UID PID PPID C STIME TTY TIME CMD
cxxu 14812 1 0 19:33 ? 00:00:00 py manage.py runserver 0:8080
cxxu 14820 14812 0 19:33 ? 00:00:17 /usr/bin/py manage.py runserver 0:8080
posted @   xuchaoxin1375  阅读(6)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-04-07 python@内置的排序方法@sort@sorted@本文文件内容排序
点击右上角即可分享
微信分享提示