id
stringlengths
16
145
text
stringlengths
1
179k
title
stringclasses
1 value
Django_meta/tutorialdjango_219_0.txt
4. Repeat the previous step to create ` templates/hello/contact.html ` using ` Contact us ` and ` <p>Contact page for the Visual Studio Code Django tutorial.</p> ` .
Django_meta/classbasedviews_55_0.txt
## Support Django!
Django_meta/modelspy_28_0.txt
def get_absolute_url(self): """Returns the url to access a particular author instance.""" return reverse('author-detail', args=[str(self.id)])
Django_meta/classbasedviews_87_0.txt
* Hosting by [ In-kind donors ](https://www.djangoproject.com/fundraising/#in-kind-donors) * Design by [ Threespot ](https://www.threespot.com) & [ andrevv ](http://andrevv.com/)
Django_meta/tutorialdjango_107_0.txt
if match_object: clean_name = match_object.group(0) else: clean_name = "Friend"
Django_meta/tutorialdjango_147_0.txt
2. Inside the ` hello ` folder, create a folder named ` templates ` , and then another subfolder named ` hello ` to match the app name (this two-tiered folder structure is typical Django convention).
Django_meta/introduction_20_0.txt
## What’s New in Django 4.2
Django_meta/tutorialdjango_52_0.txt
This ` startproject ` command assumes (by use of ` . ` at the end) that the current folder is your project folder, and creates the following within it:
Django_meta/tutorialdjango_71_0.txt
from django.http import HttpResponse
Django_meta/tutorialdjango_5_0.txt
Dismiss this update
Django_meta/introduction_44_0.txt
What do you do if you are stuck on something in this book? First, carefully check your code against what is in the book. If you’re still stuck, you can look at the official source code, which is [ available on GitHub ](https://github.com/wsvincent/djangoforbeginners) . A common error is subtle white spacing differences...
Django_meta/django_models_13_0.txt
## You are here: * [ Django 3.2 documentation ](https://docs.djangoproject.com/en/3.2/) * [ Using Django ](../../) * [ Models and databases ](../) * Models
Django_meta/tutorialdjango_305_0.txt
The following sections describe additional steps that you might find helpful in your work with Python and Visual Studio Code.
Django_meta/tutorialdjango_215_0.txt
When you select the completion, the snippet's code appears with the cursor on the snippet's insertion point:
Django_meta/tutorialdjango_125_0.txt
8. When a program is paused, the **Debug Console** panel (which is different from the "Python Debug Console" in the Terminal panel) lets you experiment with expressions and try out bits of code using the current state of the program. For example, once you've stepped over the line ` now = datetime.now() ` , you might ex...
Django_meta/tutorialdjango_337_0.txt
6/19/2023
Django_meta/tutorialdjango_69_0.txt
The command creates a folder called ` hello ` that contains a number of code files and one subfolder. Of these, you frequently work with ` views.py ` (that contains the functions that define pages in your web app) and ` models.py ` (that contains classes defining your data objects). The ` migrations ` folder is used b...
Django_meta/introduction_40_0.txt
## Advice on Getting Stuck
Django_meta/introduction_31_0.txt
The remainder of the book is dedicated to building and deploying a robust _Newspaper_ site. **Chapter 10** demonstrates how to use a custom user model, a Django best practice rarely addressed in tutorials. **Chapter 11** covers user authentication: login, logout, and signup. **Chapter 12** adds Bootstrap for enhanced C...
Django_meta/tutorialdjango_328_0.txt
The [ Docker extension ](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode- docker) makes it easy to build, manage, and deploy containerized applications from Visual Studio Code. If you're interested in learning how to create a Python container for the Django app developed in this tutorial, check...
Django_meta/tutorialdjango_10_0.txt
* [ GitHub Codespaces ](/docs/remote/codespaces) * [ VS Code Server ](/docs/remote/vscode-server) * [ Tunnels ](/docs/remote/tunnels) * [ SSH Tutorial ](/docs/remote/ssh-tutorial) * [ WSL Tutorial ](/docs/remote/wsl-tutorial) * [ Tips and Tricks ](/docs/remote/troubleshooting) * [ FAQ ](/docs/remote/faq) * Dev Containe...
Django_meta/tutorialdjango_199_0.txt
.body-content { padding: 5px; font-family:'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
Django_meta/tutorialdjango_312_0.txt
Anyone (or any build server) that receives a copy of the project needs only to run the ` pip install -r requirements.txt ` command to reinstall the packages on which the app depends within the active environment.
Django_meta/tutorialdjango_28_0.txt
# Linux sudo apt-get install python3-venv # If needed python3 -m venv .venv source .venv/bin/activate
Django_meta/tutorialdjango_333_0.txt
In this tutorial, we've only scratched the surface of everything Django can do. Be sure to visit the [ Django documentation ](https://docs.djangoproject.com/en/3.1/) and the [ official Django tutorial ](https://docs.djangoproject.com/en/3.1/intro/tutorial01/) for many more details on views, templates, data models, URL ...
Django_meta/django_models_6_0.txt
## Model attributes ¶ ` objects ` The most important attribute of a model is the [ ` Manager ` ](../managers/#django.db.models.Manager "django.db.models.Manager") . It’s the interface through which database query operations are provided to Django models and is used to [ retrieve the instances ](../queries/#...
Django_meta/django_meta_16_0.txt
### ` proxy ` ¶ ` Options. ` ` proxy ` ¶ If ` proxy = True ` , a model which subclasses another model will be treated as a [ proxy model ](../../../topics/db/models/#proxy-models) .
Django_meta/tutorialdjango_197_0.txt
.navbar-brand { font-size: 1.2em; font-weight: 600; }
Django_meta/modelspy_18_0.txt
from django.conf import settings # Required to assign User as a borrower
Django_meta/introduction_1_0.txt
[ Buy Now ](https://wsvincent.gumroad.com/l/aFiMm)
Django_meta/introduction_29_0.txt
We build our first database-backed project in **Chapter 4** , a _Message Board_ app, and then deploy it in **Chapter 5** . Django provides a powerful ORM (Object-Relational Mapper) that abstracts away the need to write raw SQL ourselves. Instead, we can write Python in a ` models.py ` file that the ORM automatically tr...
Django_meta/tutorialdjango_252_0.txt
### Use the database through the models
Django_meta/tutorialdjango_321_0.txt
3. Run the server, then open a browser to the app's /admin page (such as ` http://127.0.0.1:8000/admin ` when using the development server).
Django_meta/django_models_4_2.txt
on-model-field-options) . ### Automatic primary key fields ¶ By default, Django gives each model an auto-incrementing primary key with the type specified per app in [ ` AppConfig.default_auto_field ` ](../../../ref/applications/#django.apps.AppConfig.default_auto_field "django.apps.AppConfig.default_auto_field") o...
Django_meta/tutorialdjango_22_0.txt
2. Install a version of Python 3 (for which this tutorial is written). Options include:
Django_meta/introduction_57_0.txt
[ Home ](/) [ About ](/about/)
Django_meta/tutorialdjango_334_0.txt
To try your app on a production website, check out the tutorial [ Deploy Python apps to Azure App Service using Docker Containers ](https://learn.microsoft.com/azure/developer/python/tutorial-deploy- containers-01) . Azure also offers a standard container, [ App Service on Linux ](https://learn.microsoft.com/azure/deve...
Django_meta/tutorialdjango_182_0.txt
3. In practice, run ` collectstatic ` any time you change static files and before deploying into production.
Django_meta/tutorialdjango_258_0.txt
{% extends "hello/layout.html" %} {% block title %} Log a message {% endblock %} {% block content %} <form method="POST" class="log-form"> {% csrf_token %} {{ form.as_p }} <button type="submit" class="save btn btn-default">Log</button> </form> {% endblock %}
Django_meta/tutorialdjango_291_0.txt
17. Start the app and open a browser to the home page, which should now display messages:
Django_meta/tutorialdjango_322_0.txt
4. A login page appears, courtesy of ` django.contrib.auth ` . Enter your superuser credentials.
Django_meta/tutorialdjango_332_0.txt
The completed code project from this tutorial can be found on GitHub: [ python-sample-vscode-django-tutorial ](https://github.com/microsoft/python- sample-vscode-django-tutorial) .
Django_meta/classbasedviews_2_0.txt
__ Menu
Django_meta/django_models_10_0.txt
## Support Django! ![Support Django!](https://static.djangoproject.com/img/fundraising- heart.cd6bb84ffd33.svg) * [ Pablo Ricco donated to the Django Software Foundation to support Django development. Donate today! ](https://www.djangoproject.com/fundraising/)
Django_meta/introduction_25_0.txt
## Book Structure
Django_meta/introduction_21_0.txt
The most recent version of Django, 4.2, was released in April 2023. It has official support for Python 3.8, 3.9, 3.10, and 3.11. The official Django website contains information on all prior releases and [ detailed 4.2 release notes ](https://docs.djangoproject.com/en/4.2/releases/) .
Django_meta/introduction_16_0.txt
And best of all, Django is written in the wonderfully readable yet still powerful Python programming language. In short, if you’re building a website from scratch, Django is a fantastic choice.
Django_meta/classbasedviews_37_0.txt
We map the URL to book list view in the URLconf:
Django_meta/django_models_11_0.txt
## Contents * Models * Quick example * Using models * Fields * Field types * Field options * Automatic primary key fields * Verbose field names * Relationships * Many-to-one relationships * Many-to-many relationships * Extra fields on many...
Django_meta/tutorialdjango_48_0.txt
To create a minimal Django app, then, it's necessary to first create the Django project to serve as the container for the app, then create the app itself. For both purposes, you use the Django administrative utility, ` django-admin ` , which is installed when you install the Django package.
Django_meta/tutorialdjango_306_0.txt
### Create a requirements.txt file for the environment
Django_meta/tutorialdjango_235_0.txt
When using the ` db.sqlite3 ` file, you can also work directly with the database using a tool like the [ SQLite browser ](https://sqlitebrowser.org/) . It's fine to add or delete records in tables using such a tool, but avoid making changes to the database schema because the database will then be out of sync with your ...
Django_meta/modelspy_29_0.txt
def __str__(self): """String for representing the Model object.""" return f'{self.last_name}, {self.first_name}'
Django_meta/tutorialdjango_268_0.txt
6. One more step before you're ready to try everything out! In ` templates/hello/layout.html ` , add a link in the "navbar" div for the message logging page:
Django_meta/tutorialdjango_11_0.txt
Topics Overview Overview Linux macOS Windows Raspberry Pi Network Additional Components Enterprise Uninstall Intro Videos Tips and Tricks User Interface Themes Settings Key Bindings Display Language Telemetry Basic Editing Extension Marketplace IntelliSense Code Navigation Refactoring Debugging VS ...
Django_meta/tutorialdjango_7_0.txt
* [ Advanced ](/docs/terminal/advanced) * GitHub Copilot * [ Overview ](/docs/copilot/overview) * [ Setup ](/docs/copilot/setup) * [ Getting Started Tutorial ](/docs/copilot/getting-started) * [ Copilot Chat Tutorial ](/docs/copilot/getting-started-chat) * [ Code Completions ](/docs/copilot/ai-powered-suggestions) * [ ...
Django_meta/classbasedviews_23_0.txt
The most direct way to use generic views is to create them directly in your URLconf. If you’re only changing a few attributes on a class-based view, you can pass them into the [ ` as_view() ` ](../../ref/class-based- views/base/#django.views.generic.base.View.as_view "django.views.generic.base.View.as_view") method ca...
Django_meta/tutorialdjango_77_0.txt
from django.contrib import admin from django.urls import include, path
Django_meta/tutorialdjango_319_0.txt
2. Add the following URL route in the project-level ` urls.py ` ( ` web_project/urls.py ` in this tutorial) to point to the built-in administrative interface:
Django_meta/classbasedviews_88_0.txt
© 2005-2024 [ Django Software Foundation ](https://www.djangoproject.com/foundation/) and individual contributors. Django is a [ registered trademark ](https://www.djangoproject.com/trademarks/) of the Django Software Foundation.
Django_meta/modelspy_12_0.txt
class Meta: ordering = ['title', 'author']
Django_meta/classbasedviews_5_0.txt
Toggle theme (current theme: dark)
Django_meta/tutorialdjango_53_0.txt
* ` manage.py ` : The Django command-line administrative utility for the project. You run administrative commands for the project using ` python manage.py <command> [options] ` .
Django_meta/tutorialdjango_133_0.txt
12. Close the browser and stop the debugger when you're finished. To stop the debugger, use the Stop toolbar button (the red square) or the **Run** > **Stop Debugging** command ( ⇧F5 (Windows, Linux Shift+F5 ) ).
Django_meta/tutorialdjango_154_0.txt
You can see that the code is now much simpler, and concerned only with data values, because the markup and formatting is all contained in the template.
Django_meta/tutorialdjango_274_0.txt
10. Now modify the home page to display the logged messages. Start by replacing the contents of app's ` templates/hello/home.html ` file with the markup below. This template expects a context variable named ` message_list ` . If it receives one (checked with the ` {% if message_list %} ` tag), it then iterates over tha...
Django_meta/tutorialdjango_18_0.txt
If you have any problems, you can search for answers or ask a question on the [ Python extension Discussions Q&A ](https://github.com/microsoft/vscode- python/discussions/categories/q-a) .
Django_meta/tutorialdjango_205_0.txt
3. After VS code opens ` html.json ` , add the code below within the existing curly braces. (The explanatory comments, not shown here, describe details such as how the ` $0 ` line indicates where VS Code places the cursor after inserting a snippet):
Django_meta/classbasedviews_8_0.txt
Toggle theme (current theme: light)
Django_meta/tutorialdjango_120_0.txt
5. Output appears in a "Python Debug Console" terminal. Open a browser and navigate to ` http://127.0.0.1:8000/hello/VSCode ` . Before the page renders, VS Code pauses the program at the breakpoint you set. The small yellow arrow on the breakpoint indicates that it's the next line of code to run.
Django_meta/tutorialdjango_288_0.txt
home_list_view = views.HomeListView.as_view( queryset=LogMessage.objects.order_by("-log_date")[:5], # :5 limits the results to the five most recent context_object_name="message_list", template_name="hello/home.html", )
Django_meta/introduction_6_0.txt
## Prerequisites
Django_meta/tutorialdjango_102_0.txt
2. Replace the contents of ` views.py ` with the following code to define the ` hello_there ` function that you can step through in the debugger:
Django_meta/tutorialdjango_134_0.txt
> **Tip** : To make it easier to repeatedly navigate to a specific URL like ` > http://127.0.0.1:8000/hello/VSCode ` , output that URL using a ` print ` > statement somewhere in a file like ` views.py ` . The URL appears in the VS > Code Terminal where you can use Ctrl+click to open it in a browser.
Django_meta/modelspy_27_0.txt
class Meta: ordering = ['last_name', 'first_name']
Django_meta/tutorialdjango_309_0.txt
Although you can create the file by hand, you can also use the ` pip freeze ` command to generate the file based on the exact libraries installed in the activated environment:
Django_meta/tutorialdjango_66_0.txt
### Create a Django app
Django_meta/introduction_45_0.txt
The next step is to walk away from the computer or even sleep on the problem. It’s incredible what a small amount of rest and distance will do to your mind when solving problems.
Django_meta/django_models_16_0.txt
## Learn More * [ About Django ](https://www.djangoproject.com/start/overview/) * [ Getting Started with Django ](https://www.djangoproject.com/start/) * [ Team Organization ](https://docs.djangoproject.com/en/dev/internals/organization/) * [ Django Software Foundation ](https://www.djangoproject.com/foundati...
Django_meta/classbasedviews_29_0.txt
# some_app/views.py from django.views.generic import TemplateView
Django_meta/tutorialdjango_16_0.txt
In this Django tutorial, you create a simple Django app with three pages that use a common base template. You create this app in the context of Visual Studio Code in order to understand how to work with Django in the VS Code terminal, editor, and debugger. This tutorial does not explore various details about Django its...
Django_meta/tutorialdjango_34_0.txt
![Django tutorial: opening the Command Palette in VS Code](/assets/docs/python/shared/command-palette.png)
Django_meta/tutorialdjango_262_0.txt
4. In the app's ` urls.py ` file, add a route for the new page:
Django_meta/tutorialdjango_198_0.txt
.navbar-item { font-variant: small-caps; margin-left: 30px; }
Django_meta/classbasedviews_30_0.txt
class AboutView(TemplateView): template_name = "about.html"
Django_meta/introduction_50_0.txt
## Conclusion
Django_meta/tutorialdjango_224_0.txt
def about(request): return render(request, "hello/about.html")
Django_meta/tutorialdjango_37_0.txt
6. Run [ **Terminal: Create New Terminal** ](/docs/terminal/basics) ( ⌃⇧` (Windows, Linux Ctrl+Shift+` ) ) from the Command Palette, which creates a terminal and automatically activates the virtual environment by running its activation script.
Django_meta/tutorialdjango_56_0.txt
python manage.py migrate
Django_meta/classbasedviews_41_0.txt
from django.http import HttpResponse from django.views.generic import ListView from books.models import Book
Django_meta/classbasedviews_45_0.txt
## Asynchronous class-based views ¶
Django_meta/tutorialdjango_92_0.txt
5. Ctrl+click the ` http://127.0.0.1:8000/ ` URL in the terminal output window to open the browser and see that the app is running properly.
Django_meta/introduction_38_0.txt
For brevity, we will use three dots, ` ... ` , when the existing code has not changed. The section of code that _has_ changed is highlighted using a ` # new ` comment.
Django_meta/introduction_34_0.txt
By the end of this book, you’ll have a solid understanding of Django, the ability to build your apps, and the background required to fully take advantage of additional resources for learning intermediate and advanced Django techniques.
Django_meta/tutorialdjango_194_0.txt
2. Add the following styles to ` static/hello/site.css ` below the existing "message" style, and save the file. (This walkthrough doesn't attempt to demonstrate responsive design; these styles simply generate a reasonably interesting result.)
Django_meta/tutorialdjango_51_0.txt
django-admin startproject web_project .
Django_meta/tutorialdjango_146_0.txt
'hello',
Django_meta/classbasedviews_27_0.txt
## Subclassing generic views ¶
Django_meta/modelspy_23_0.txt
class Meta: ordering = ['due_back'] permissions = (("can_mark_returned", "Set book as returned"),)
Django_meta/tutorialdjango_316_0.txt
Perform the following steps to enable the administrative interface: