English 中文(简体)
如何没收《演播室视觉法》,以便把Django装在虚拟时代?
原标题:How to configure Visual Studio Code to debug Django app in a virtualenv?

I would like to have possibility to do a debugging of Django application in Visual Studio Code. I have a virtualenv, made a change in launch.json file that look like this:

{
    "name": "Django",
    "type": "python",
    "request": "launch",
    "stopOnEntry": true,
    "pythonPath": "${workspaceRoot}/.venv/bin/python2.7",
    "program": "${workspaceRoot}/mysite/manage.py",
    "args": [
        "runserver"
    ],
    "debugOptions": [
        "WaitOnAbnormalExit",
        "WaitOnNormalExit",
        "DjangoDebugging",
        "RedirectOutput"
    ]
},

守则中有若干条断点。 不幸的是,处决没有停止。 我尝试了同样的事,一切都完美无缺。

请指出我在这里做的错。

最佳回答

对我来说,以下2个改动是行之有效的。

  1. Add an absolute path for pythonPath
  2. Use the "--noreload" option while starting the project

这里指的是我会议的相关部分。

    {
        "name": "Django",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "/Users/xyz/Documents/dev/my_project/my_project_env/bin/python",
        "program": "${workspaceRoot}/manage.py",
        "args": [
            "runserver",
            "0.0.0.0:8080",
            "--noreload"                
        ],
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput",
            "DjangoDebugging"
        ]
    },
问题回答

1) Press CTRL + ,
2) Select Workspace Settings
3) Add the following line in the settings file opened.

"python.pythonPath": "path_to_your_env"


You re done!

这位官方辅导员在我的案件中工作。

有必要打开《科索沃法典》的“通棕榈”并选择我的“灵魂”进入虚拟环境:

“entergraph

“entergraph

Full reference: https://code.visualstudio.com/docs/python/tutorial-django#_create-a-project-environment-for-the-django-tutorial

如果你在视力演播室守则中打开其他录音带,你可以:

  1. recreate the venv file

python3 -m venv venv

python -m venv venv

  1. copy paste the 或iginal files except(pyvenv.cfg)

  2. Select the interpreter https://code.visualstudio.com/docs/python/tut或ial-django#_create-a-project-environment-f或-the-django-tut或ial

  3. 以下用途: json:

    { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // F或 m或e inf或mation, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [

         {
             "name": "Python: Django",
             "type": "debugpy",
             "request": "launch",
             "python":"${w或kspaceFolderiii/venv/Scripts/python.exe",
             "program": "${w或kspaceFolderiii\manage.py",
             "args": [
                 "runserver"
             ],
             "django": true,
             "justMyCode": true
         iii
     ]
    

    iii





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签