microsoft / vscode-python

Python extension for Visual Studio Code
https://aka.ms/pvsc-marketplace
MIT License
4.25k stars 1.15k forks source link

Open browser after launching a Django or flask app #1058

Closed DonJayamanne closed 6 months ago

DonJayamanne commented 6 years ago

Investigate the possibility of launching the browser once a django/flask app has been started

Some other IDEs (PTVS) do this today

brettcannon commented 6 years ago

How do you know what port to open? Would we prompt for that and then just open localhost? Would you specify in your launch.json, but then how do you keep it synced with the code? Would probably require people specifying the URL to launch in launch.json.

brettcannon commented 5 years ago

To help manage our issues and to better communicate what the team plans to work on we are closing issues that we don't plan to work on but would accept a pull request from a volunteer for. To be clear, closing this issue does not mean we won't consider a pull request for this enhancement as outlined in our contributing guide, just that the development team has no plans to work on it themselves.

DonJayamanne commented 5 years ago

Re-opening as other extensions are looking at doing this, C# extension does this today (or are in the process of doing this). They are scraping the debugger output to extract the url.

Also, it makes sense, i.e. when you start debugging a web application the next logical step is to open a browser.

qubitron commented 5 years ago

We would need to figure out how this would work in remote scenarios.

DonJayamanne commented 5 years ago

This feature has landed in VS Code.

We might want to implement this at least for local debugging and consider a seprate issue for remote scenarios.

FYI - Its just a configuration setting in launch.json, not typescript code etc..

DonJayamanne commented 5 years ago
karrtikr commented 4 years ago

Prescribed solution

karthiknadig commented 4 years ago

I have another issue here with regex for Django and Flask.

karrtikr commented 4 years ago

@karthiknadig Can you elaborate on that?

karrtikr commented 4 years ago

Flask outputs comes out to be something like this,

 * Serving Flask app "app.py"
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

So I am planning to use,

"serverReadyAction": {
    "pattern": "Running on http://([0-9]+[.][0-9]+[.][0-9]+[.][0-9]+:[0-9]+)",
    "uriFormat": "http://%s",
    "action": "openExternally"
}

Similar for django. By observation, it looks like we'll have http://number.number.number.number:<number> present. So having that as default seems fine to me. Any objections? @karthiknadig @ericsnowcurrently @DonJayamanne

karthiknadig commented 4 years ago

See here for patterns that worked for me: https://github.com/microsoft/vscode-python/issues/5192#issue-431688484

Note: that it may not always be 127.0.0.1, host can be localhost, loopback, etc. Also, "Running on" may not be there in some cases. SSL can be enabled on those frameworks as well, so just http is not enough either. The pattern in my comment has limitations too, for example it does not handle IPv6 host, but it should be a good starting point to test.

karthiknadig commented 4 years ago

@Anapo14 Spec for this is done right?

luabud commented 4 years ago

Changes will be here https://github.com/microsoft/vscode-python/blob/master/src/client/debugger/extension/configuration/resolvers/base.ts. If user is in experiment, look at the same markers (django, flask, pyramid, jinja), see if serverReadyAction is openExternally, replace value with:

image.png

Add logging and telemetry for this change.

paulacamargo25 commented 6 months ago

Adding this issue here to the Python Debugger repository.