Giter Site home page Giter Site logo

microsoft / python-sample-vscode-django-tutorial Goto Github PK

View Code? Open in Web Editor NEW
167.0 26.0 181.0 45 KB

Sample code for the Django tutorial in the VS Code documentation

Home Page: https://code.visualstudio.com/docs/python/tutorial-django

License: MIT License

Python 66.04% CSS 4.72% HTML 17.68% Dockerfile 11.56%

python-sample-vscode-django-tutorial's Introduction

This sample contains the completed program from the tutorial, Using Django in Visual Studio Code. Intermediate steps are not included.

The sample also includes a Dockerfile to build a production-ready container image that uses uwsgi and nginx; the uwsgi.ini file provides uwsgi configuration.

To run the sample:

  1. Create a virtual environment as described in the tutorial.
  2. Install packages with pip install -r requirements.txt.
  3. Activate the virtual environment by running source env/bin/activate (Linux/MacOS) or env\scripts\activate (Windows).
  4. Create and initialize the database by running python manage.py migrate.
  5. Create a superuser as described at the end of the tutorial.

Contributions to the sample are welcome. When submitting changes, also consider submitting matching changes to the tutorial, the source file for which is tutorial-django.md.

Known issues

  • CSS is lost if you set DEBUG=False in settings.py; the workaround is to include an added script at the end of dockerfile.txt to serve static file differently. See Issue 13 for details.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

python-sample-vscode-django-tutorial's People

Contributors

billykern avatar brettcannon avatar browniebroke avatar cpmaurya avatar cwebster-99 avatar jpapp25 avatar karansthr avatar kraigb avatar microsoft-github-policy-service[bot] avatar microsoftopensource avatar mohi7solanki avatar msftgits avatar nnja avatar stutibiyani avatar supriyanta avatar tonybaloney avatar xadahiya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-sample-vscode-django-tutorial's Issues

When building with debug = false css is lost

@kraigb
Static files don't seem to be served when debug = false.

To replicate in vs code + win 10:

  1. Git clone
  2. remove python==3.7 from requirements (wont build otherwise)
  3. Docker build
  4. Docker run locally
  5. Everything fine
  6. Set debug=False
  7. Docker build
  8. Docker run locally
  9. remember to ctrl+f5 refresh page.
    No CSS loading. It seems static files are missing...

I tried pushing to webapp with same result. Am i missing something?

Remove potentially confusing "Python: Flask" launch configuration

.vscode/launch.json contains a "Python: Flask" configuration.
This feels a bit confusing, seeing as one probably wants to launch the "Python: django" instead.
Most users are probably clever enough to select the correct one, but one could be confused.

I can send a quick PR with the removal of the "Python: Flask" configuration if that's something you'd want?

404 error

I wrote a working Django project in vscode I run the code on server is saying wrong code why the code is correct

chmod: /app/db.sqlite3: No such file or directory + error: command 'gcc' failed: No such file or directory

After following https://code.visualstudio.com/docs/containers/docker-compose and run docker-compose up:

docker-compose up
Creating network "python-sample-vscode-django-tutorial_default" with the default driver
Building pythonsamplevscodedjangotutorial
[+] Building 0.8s (9/11)                                                                                                                                                                   docker:default
 => [internal] load .dockerignore                                                                                                                                                                    0.0s
 => => transferring context: 155B                                                                                                                                                                    0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                 0.0s
 => => transferring dockerfile: 1.75kB                                                                                                                                                               0.0s
 => [internal] load metadata for docker.io/tiangolo/uwsgi-nginx:python3.8-alpine-2020-12-19                                                                                                          0.4s
 => [1/7] FROM docker.io/tiangolo/uwsgi-nginx:python3.8-alpine-2020-12-19@sha256:64f9b860c7987128c0c817b5ac68ff2070188e8e397bb3a89a51add5495c4dbf                                                    0.0s
 => [internal] load build context                                                                                                                                                                    0.0s
 => => transferring context: 1.30kB                                                                                                                                                                  0.0s
 => CACHED [2/7] WORKDIR /app                                                                                                                                                                        0.0s
 => CACHED [3/7] ADD . /app                                                                                                                                                                          0.0s
 => CACHED [4/7] RUN chmod g+w /app                                                                                                                                                                  0.0s
 => ERROR [5/7] RUN chmod g+w /app/db.sqlite3                                                                                                                                                        0.4s
------
 > [5/7] RUN chmod g+w /app/db.sqlite3:
0.330 chmod: /app/db.sqlite3: No such file or directory
------
Dockerfile:34
--------------------
  32 |     # write to the database.
  33 |     RUN chmod g+w /app
  34 | >>> RUN chmod g+w /app/db.sqlite3
  35 |     RUN pip install debugpy
  36 |     # Make sure dependencies are installed
--------------------

and feel errors is due to following

RUN chmod g+w /app/db.sqlite3

If comment out above line, docker-compose up will result in

 docker-compose up
Building pythonsamplevscodedjangotutorial
[+] Building 3.8s (9/9) FINISHED                                                                                                                                                           docker:default
 => [internal] load build definition from Dockerfile                                                                                                                                                 0.0s
 => => transferring dockerfile: 1.75kB                                                                                                                                                               0.0s
 => [internal] load .dockerignore                                                                                                                                                                    0.0s
 => => transferring context: 155B                                                                                                                                                                    0.0s
 => [internal] load metadata for docker.io/tiangolo/uwsgi-nginx:python3.8-alpine-2020-12-19                                                                                                          0.3s
 => [1/5] FROM docker.io/tiangolo/uwsgi-nginx:python3.8-alpine-2020-12-19@sha256:64f9b860c7987128c0c817b5ac68ff2070188e8e397bb3a89a51add5495c4dbf                                                    0.0s
 => [internal] load build context                                                                                                                                                                    0.0s
 => => transferring context: 1.30kB                                                                                                                                                                  0.0s
 => CACHED [2/5] WORKDIR /app                                                                                                                                                                        0.0s
 => CACHED [3/5] ADD . /app                                                                                                                                                                          0.0s
 => CACHED [4/5] RUN chmod g+w /app                                                                                                                                                                  0.0s
 => ERROR [5/5] RUN python3 -m pip install -r requirements.txt                                                                                                                                       3.4s
------                                                                                                                                                                                                    
 > [5/5] RUN python3 -m pip install -r requirements.txt:                                                                                                                                                  
1.204 Collecting pytz==2020.5                                                                                                                                                                             
1.289   Downloading pytz-2020.5-py2.py3-none-any.whl (510 kB)                                                                                                                                             
1.358 Collecting Django>=3.1.0                                                                                                                                                                            
1.376   Downloading Django-4.2.8-py3-none-any.whl (8.0 MB)                                                                                                                                                
1.670 Collecting asgiref<4,>=3.6.0
1.687   Downloading asgiref-3.7.2-py3-none-any.whl (24 kB)
1.736 Collecting sqlparse>=0.3.1
1.751   Downloading sqlparse-0.4.4-py3-none-any.whl (41 kB)
1.763 Collecting typing-extensions>=4
1.779   Downloading typing_extensions-4.9.0-py3-none-any.whl (32 kB)
1.788 Collecting backports.zoneinfo
1.809   Downloading backports.zoneinfo-0.2.1.tar.gz (74 kB)
1.827   Installing build dependencies: started
2.971   Installing build dependencies: finished with status 'done'
2.971   Getting requirements to build wheel: started
3.075   Getting requirements to build wheel: finished with status 'done'
3.077     Preparing wheel metadata: started
3.180     Preparing wheel metadata: finished with status 'done'
3.184 Building wheels for collected packages: backports.zoneinfo
3.185   Building wheel for backports.zoneinfo (PEP 517): started
3.316   Building wheel for backports.zoneinfo (PEP 517): finished with status 'error'
3.316   ERROR: Command errored out with exit status 1:
3.316    command: /usr/local/bin/python3 /usr/local/lib/python3.8/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /tmp/tmpzgg2ogsf
3.316        cwd: /tmp/pip-install-wvyw298l/backports-zoneinfo_cbd24a43807349dd87151104a2f7156e
3.316   Complete output (35 lines):
3.316   running bdist_wheel
3.316   running build
3.316   running build_py
3.316   creating build
3.316   creating build/lib.linux-x86_64-cpython-38
3.316   creating build/lib.linux-x86_64-cpython-38/backports
3.316   copying src/backports/__init__.py -> build/lib.linux-x86_64-cpython-38/backports
3.316   creating build/lib.linux-x86_64-cpython-38/backports/zoneinfo
3.316   copying src/backports/zoneinfo/_tzpath.py -> build/lib.linux-x86_64-cpython-38/backports/zoneinfo
3.316   copying src/backports/zoneinfo/_version.py -> build/lib.linux-x86_64-cpython-38/backports/zoneinfo
3.316   copying src/backports/zoneinfo/_common.py -> build/lib.linux-x86_64-cpython-38/backports/zoneinfo
3.316   copying src/backports/zoneinfo/__init__.py -> build/lib.linux-x86_64-cpython-38/backports/zoneinfo
3.316   copying src/backports/zoneinfo/_zoneinfo.py -> build/lib.linux-x86_64-cpython-38/backports/zoneinfo
3.316   running egg_info
3.316   writing src/backports.zoneinfo.egg-info/PKG-INFO
3.316   writing dependency_links to src/backports.zoneinfo.egg-info/dependency_links.txt
3.316   writing requirements to src/backports.zoneinfo.egg-info/requires.txt
3.316   writing top-level names to src/backports.zoneinfo.egg-info/top_level.txt
3.316   reading manifest file 'src/backports.zoneinfo.egg-info/SOURCES.txt'
3.316   reading manifest template 'MANIFEST.in'
3.316   warning: no files found matching '*.png' under directory 'docs'
3.316   warning: no files found matching '*.svg' under directory 'docs'
3.316   no previously-included directories found matching 'docs/_build'
3.316   no previously-included directories found matching 'docs/_output'
3.316   adding license file 'LICENSE'
3.316   adding license file 'licenses/LICENSE_APACHE'
3.316   writing manifest file 'src/backports.zoneinfo.egg-info/SOURCES.txt'
3.316   copying src/backports/zoneinfo/__init__.pyi -> build/lib.linux-x86_64-cpython-38/backports/zoneinfo
3.316   copying src/backports/zoneinfo/py.typed -> build/lib.linux-x86_64-cpython-38/backports/zoneinfo
3.316   running build_ext
3.316   building 'backports.zoneinfo._czoneinfo' extension
3.316   creating build/temp.linux-x86_64-cpython-38
3.316   creating build/temp.linux-x86_64-cpython-38/lib
3.316   gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/local/include/python3.8 -c lib/zoneinfo_module.c -o build/temp.linux-x86_64-cpython-38/lib/zoneinfo_module.o -std=c99
3.316   error: command 'gcc' failed: No such file or directory
3.316   ----------------------------------------
3.316   ERROR: Failed building wheel for backports.zoneinfo
3.316 Failed to build backports.zoneinfo
3.316 ERROR: Could not build wheels for backports.zoneinfo which use PEP 517 and cannot be installed directly
3.322 WARNING: You are using pip version 20.3.3; however, version 23.3.2 is available.
3.322 You should consider upgrading via the '/usr/local/bin/python3 -m pip install --upgrade pip' command.
------
Dockerfile:37
--------------------
  36 |     # Make sure dependencies are installed
  37 | >>> RUN python3 -m pip install -r requirements.txt
  38 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c python3 -m pip install -r requirements.txt" did not complete successfully: exit code: 1
ERROR: Service 'pythonsamplevscodedjangotutorial' failed to build : Build failed

Remove python==3.7 from requirements.txt

I'm not sure why python==3.7 was added to requirements.txt but it doesn't work on windows (not sure if it's supposed to work on mac/linux):

(.venv) C:\dev\python-sample-vscode-django-tutorial>pip install -r requirements.txt
Collecting Django>=2.1.2 (from -r requirements.txt (line 1))
  Using cached https://files.pythonhosted.org/packages/d1/e5/2676be45ea49cfd09a663f289376b3888accd57ff06c953297bfdee1fb08/Django-2.1.3-py3-none-any.whl
Collecting pytz==2018.5 (from -r requirements.txt (line 2))
  Using cached https://files.pythonhosted.org/packages/30/4e/27c34b62430286c6d59177a0842ed90dc789ce5d1ed740887653b898779a/pytz-2018.5-py2.py3-none-any.whl
Collecting Python==3.7 (from -r requirements.txt (line 3))
  Could not find a version that satisfies the requirement Python==3.7 (from -r requirements.txt (line 3)) (from versions: )
No matching distribution found for Python==3.7 (from -r requirements.txt (line 3))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.