id stringlengths 16 145 | text stringlengths 1 179k | title stringclasses 1
value |
|---|---|---|
Django_meta/tutorialdjango_6_0.txt | * [ Overview ](/docs)
* Setup
* [ Overview ](/docs/setup/setup-overview)
* [ Linux ](/docs/setup/linux)
* [ macOS ](/docs/setup/mac)
* [ Windows ](/docs/setup/windows)
* [ Raspberry Pi ](/docs/setup/raspberry-pi)
* [ Network ](/docs/setup/network)
* [ Additional Components ](/docs/setup/additional-components)
* [ Enter... | |
Django_meta/tutorialdjango_259_0.txt |
> **Note** : Django's ` {% csrf_token %} ` tag provides protection from cross-
> site request forgeries. See [ Cross Site Request Forgery protection
> ](https://docs.djangoproject.com/en/3.1/ref/csrf/) in the Django
> documentation for details. | |
Django_meta/modelspy_5_0.txt | def get_absolute_url(self):
"""Returns the url to access a particular genre instance."""
return reverse('genre-detail', args=[str(self.id)]) | |
Django_meta/tutorialdjango_20_0.txt | To successfully complete this Django tutorial, you must do the following
(which are the same steps as in the [ general Python tutorial
](/docs/python/python-tutorial) ): | |
Django_meta/classbasedviews_60_0.txt | ## Browse | |
Django_meta/tutorialdjango_97_0.txt | **Before you begin** : Make sure you've stopped the running app at the end of
the last section by using Ctrl+C in the terminal. If you leave the app
running in one terminal, it continues to own the port. As a result, when you
run the app in the debugger using the same port, the original running app
handles all the re... | |
Django_meta/classbasedviews_57_0.txt | * [ Trey Hunner donated to the Django Software Foundation to support Django development. Donate today! ](https://www.djangoproject.com/fundraising/) | |
Django_meta/tutorialdjango_263_0.txt | path("log/", views.log_message, name="log"), | |
Django_meta/tutorialdjango_326_0.txt | You can customize the administrative interface as much as you like. For
example, you could provide capabilities to edit and remove entries in the
database. For more information on making customizations, refer to the [ Django
admin site documentation
](https://docs.djangoproject.com/en/3.1/ref/contrib/admin/) . | |
Django_meta/introduction_54_0.txt | Continue on to [ Chapter 1: Initial Set Up ](/initial-setup/) . | |
Django_meta/tutorialdjango_177_0.txt | ### Use the collectstatic command | |
Django_meta/tutorialdjango_129_0.txt | now.strftime("%A, %d %B, %Y at %X")
'Tuesday, 13 June, 2023 at 18:03:19'
now.strftime("%a, %d %b, %Y at %X")
'Tue, 13 Jun, 2023 at 18:03:19'
now.strftime("%a, %d %b, %y at %X")
'Tue, 13 Jun, 23 at 18:03:19' | |
Django_meta/introduction_13_0.txt | This approach allows web developers to focus on what makes a web application
unique rather than reinventing the wheel every time. | |
Django_meta/tutorialdjango_254_0.txt | 1. In the ` hello ` folder (where you have ` views.py ` ), create a new file named ` forms.py ` with the following code, which defines a Django form that contains a field drawn from the data model, ` LogMessage ` : | |
Django_meta/django_models_18_0.txt | ## Get Help
* [ Getting Help FAQ ](https://docs.djangoproject.com/en/stable/faq/)
* [ #django IRC channel ](irc://irc.libera.chat/django)
* [ Django Discord ](https://discord.gg/xcRH6mN4fa)
* [ Official Django Forum ](https://forum.djangoproject.com/)
| |
Django_meta/tutorialdjango_327_0.txt | ### Create a container for a Django app using the Docker extension | |
Django_meta/introduction_52_0.txt | ## Conclusion | |
Django_meta/django_meta_10_0.txt | ### ` get_latest_by ` ¶
` Options. ` ` get_latest_by ` ¶
The name of a field or a list of field names in the model, typically [ `
DateField ` ](../fields/#django.db.models.DateField
"django.db.models.DateField") , [ ` DateTimeField `
](../fields/#django.db.models.DateTimeField "django.db.models.DateTimeFi... | |
Django_meta/django_meta_14_0.txt | ### ` permissions ` ¶
` Options. ` ` permissions ` ¶
Extra permissions to enter into the permissions table when creating this
object. Add, change, delete, and view permissions are automatically created
for each model. This example specifies an extra permission, `
can_deliver_pizzas ` :
permi... | |
Django_meta/tutorialdjango_117_0.txt |  | |
Django_meta/tutorialdjango_176_0.txt |
6. Run the app, navigate to a /hello/name URL, and observe that the message renders in blue. Stop the app when you're done. | |
Django_meta/tutorialdjango_289_0.txt |
16. In ` urls.py ` , modify the path to the home page to use the ` home_list_view ` variable: | |
Django_meta/tutorialdjango_144_0.txt | In this section, you start by creating a single page using a template. In
subsequent sections, you configure the app to serve static files and then
create multiple pages to the app that each contains a nav bar from a base
template. Django templates also support control flow and iteration, as you see
later in this tutor... | |
Django_meta/classbasedviews_84_0.txt | ## Support Us | |
Django_meta/tutorialdjango_32_0.txt | 3. Open the project folder in VS Code by running ` code . ` , or by running VS Code and using the **File** > **Open Folder** command. | |
Django_meta/tutorialdjango_115_0.txt |  | |
Django_meta/tutorialdjango_308_0.txt | Accordingly, developers typically omit the virtual environment folder from
source control and instead describe the app's dependencies using a `
requirements.txt ` file. | |
Django_meta/django_models_8_5.txt | l setting of [ ` Meta.db_table `
](../../../ref/models/options/#django.db.models.Options.db_table
"django.db.models.Options.db_table") you could create an unmanaged model that
shadows an existing model and adds Python methods to it. However, that would
be very repetitive and fragile as you need to keep both copies syn... | |
Django_meta/tutorialdjango_40_0.txt |  | |
Django_meta/tutorialdjango_300_0.txt |  | |
Django_meta/introduction_22_0.txt | One of the significant efforts for Django since 3.0 has been adding
asynchronous support. Django 3.0 added ASGI (Asynchronous Server Gateway
Interface), while Django 3.1 included asynchronous views, middleware, tests,
and test client. Django 4.0 began making cache backends async-compatible, and
Django 4.1 added both as... | |
Django_meta/django_meta_26_0.txt | ### ` label ` ¶
` Options. ` ` label ` ¶
Representation of the object, returns ` app_label.object_name ` , e.g. `
'polls.Question' ` .
| |
Django_meta/tutorialdjango_233_0.txt | The migration scripts effectively record all the incremental changes you make
to your data models over time. By applying the migrations, Django updates the
database to match your models. Because each incremental change has its own
script, Django can automatically migrate _any_ previous version of a database
(including ... | |
Django_meta/classbasedviews_72_0.txt | Report bugs with Django or Django documentation in our ticket tracker. | |
Django_meta/classbasedviews_32_0.txt | # urls.py
from django.urls import path
from some_app.views import AboutView | |
Django_meta/modelspy_15_0.txt | def get_absolute_url(self):
"""Returns the url to access a particular book record."""
return reverse('book-detail', args=[str(self.id)]) | |
Django_meta/tutorialdjango_60_0.txt | System check identified no issues (0 silenced).
June 13, 2023 - 18:38:07
Django version 4.2.2, using settings 'web_project.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK. | |
Django_meta/tutorialdjango_192_0.txt | <body>
<div class="navbar">
<a href="{% url 'home' %}" class="navbar-brand">Home</a>
<a href="{% url 'about' %}" class="navbar-item">About</a>
<a href="{% url 'contact' %}" class="navbar-item">Contact</a>
</div> | |
Django_meta/classbasedviews_62_0.txt | ## You are here: | |
Django_meta/tutorialdjango_90_0.txt | 4. Test the configuration by selecting the **Run** > **Start Debugging** menu command, or selecting the green **Start Debugging** arrow next to the list ( F5 ): | |
Django_meta/tutorialdjango_93_0.txt | 6. 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/classbasedviews_46_0.txt | As well as the synchronous ( ` def ` ) method handlers already shown, ` View
` subclasses may define asynchronous ( ` async def ` ) method handlers to
leverage asynchronous code using ` await ` : | |
Django_meta/tutorialdjango_94_0.txt | 7. You can now use the **Run** > **Start Debugging** at any time to test the app, which also has the benefit of automatically saving all modified files. | |
Django_meta/tutorialdjango_216_0.txt |  | |
Django_meta/tutorialdjango_145_0.txt | 1. In the ` web_project/settings.py ` file, locate the ` INSTALLED_APPS ` list and add the following entry, which makes sure the project knows about the app so it can handle templating: | |
Django_meta/classbasedviews_61_0.txt | * Prev: [ Templates ](../templates/)
* Next: [ Introduction to class-based views ](intro/)
* [ Table of contents ](https://docs.djangoproject.com/en/5.0/contents/)
* [ General Index ](https://docs.djangoproject.com/en/5.0/genindex/)
* [ Python Module Index ](https://docs.djangoproject.com/en/5.0/py-modindex/) | |
Django_meta/tutorialdjango_299_0.txt | 2. Run the app in the debugger and open a browser to the home page. (If you're already running the debugger, you don't have to restart the app after setting breakpoints; just refresh the page.) Observe that VS Code breaks into the debugger in the template on the ` {% if %} ` statement and shows all the context variable... | |
Django_meta/tutorialdjango_214_0.txt |  | |
Django_meta/classbasedviews_43_0.txt | def head(self, *args, **kwargs):
last_book = self.get_queryset().latest("publication_date")
response = HttpResponse(
# RFC 1123 date format.
headers={
"Last-Modified": last_book.publication_date.strftime(
"%a, %d %b %Y %H:%M:%S GMT"
)
},
)
return response | |
Django_meta/introduction_10_0.txt | A “web framework” is a collection of tools that abstract away much of the
difficulty–and repetition–inherent in web development. For example, most
websites need the same basic functionality: the ability to connect to a
database, set URL routes, display content on a page, handle security properly,
and so on. Rather than... | |
Django_meta/tutorialdjango_307_0.txt | When you share your app code through source control or some other means, it
doesn't make sense to copy all the files in a virtual environment because
recipients can always recreate that environment themselves. | |
Django_meta/tutorialdjango_70_0.txt | 2. Modify ` hello/views.py ` to match the following code, which creates a single view for the app's home page: | |
Django_meta/tutorialdjango_310_0.txt | 1. With your chosen environment selected using the **Python: Select Interpreter** command, run the **Terminal: Create New Terminal** command ( ⌃⇧` (Windows, Linux Ctrl+Shift+` ) )) to open a terminal with that environment activated. | |
Django_meta/tutorialdjango_62_0.txt | If you want to use a different port than the default 8000, specify the port
number on the command line, such as ` python manage.py runserver 5000 ` . | |
Django_meta/modelspy_4_0.txt | def __str__(self):
"""String for representing the Model object (in Admin site etc.)"""
return self.name | |
Django_meta/classbasedviews_14_0.txt | * [ el ](https://docs.djangoproject.com/el/5.0/topics/class-based-views/)
* [ es ](https://docs.djangoproject.com/es/5.0/topics/class-based-views/)
* [ fr ](https://docs.djangoproject.com/fr/5.0/topics/class-based-views/)
* [ id ](https://docs.djangoproject.com/id/5.0/topics/class-based-views/)
* [ it ](https://docs.dj... | |
Django_meta/tutorialdjango_195_0.txt | .navbar {
background-color: lightslategray;
font-size: 1em;
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
color: white;
padding: 8px 5px 8px 5px;
} | |
Django_meta/classbasedviews_73_0.txt | ## Download: | |
Django_meta/django_meta_4_0.txt | ### ` base_manager_name ` ¶
` Options. ` ` base_manager_name ` ¶
The attribute name of the manager, for example, ` 'objects' ` , to use for
the model’s [ ` _base_manager `
](../../../topics/db/managers/#django.db.models.Model._base_manager
"django.db.models.Model._base_manager") .
| |
Django_meta/tutorialdjango_141_0.txt | The app you've created so far in this tutorial generates only plain text web
pages from Python code. Although it's possible to generate HTML directly in
code, developers avoid such a practice because it opens the app to [ cross-
site scripting (XSS) attacks ](https://en.wikipedia.org/wiki/Cross-
site_scripting) . In th... | |
Django_meta/tutorialdjango_38_0.txt | > **Note** : On Windows, if your default terminal type is PowerShell, you may
> see an error that it cannot run activate.ps1 because running scripts is
> disabled on the system. The error provides a link for information on how to
> allow scripts. Otherwise, use **Terminal: Select Default Profile** to set
> "Command Pro... | |
Django_meta/modelspy_17_0.txt |
import uuid # Required for unique book instances
from datetime import date | |
Django_meta/tutorialdjango_314_0.txt | ### Create a superuser and enable the administrative interface | |
Django_meta/tutorialdjango_290_0.txt | # Replace the existing path for ""
path("", home_list_view, name="home"), | |
Django_meta/tutorialdjango_118_0.txt | A debugging toolbar (shown below) also appears in VS Code containing commands
in the following order: Pause (or Continue, F5 ), Step Over ( F10 ), Step
Into ( F11 ), Step Out ( ⇧F11 (Windows, Linux Shift+F11 ) ), Restart (
⇧⌘F5 (Windows, Linux Ctrl+Shift+F5 ) ), and Stop ( ⇧F5 (Windows, Linux
Shift+F5 ... | |
Django_meta/tutorialdjango_42_0.txt | python -m pip install --upgrade pip | |
Django_meta/tutorialdjango_281_0.txt |
13. Also in ` views.py ` , replace the ` home ` function with a _class_ named ` HomeListView ` , derived from ` ListView ` , which ties itself to the ` LogMessage ` model and implements a function ` get_context_data ` to generate the context for the template. | |
Django_meta/introduction_18_0.txt | I wrote this book because while Django has incredible documentation, there
need to be more beginner-friendly tutorials. The documentation assumes you
already know what you want to do and provides relatively terse explanations
aimed at intermediate-to-advanced developers; tutorials are typically more
geared towards begi... | |
Django_meta/classbasedviews_12_0.txt | Search: __ Search | |
Django_meta/tutorialdjango_185_0.txt | Also, because you'll likely create many pages that extend the same template,
it's helpful to create a code snippet in VS Code with which you can quickly
initialize new page templates. A snippet helps you avoid tedious and error-
prone copy-paste operations. | |
Django_meta/modelspy_6_0.txt | class Meta:
constraints = [
UniqueConstraint(
Lower('name'),
name='genre_name_case_insensitive_unique',
violation_error_message = "Genre already exists (case insensitive match)"
),
] | |
Django_meta/django_meta_8_0.txt | ### ` default_manager_name ` ¶
` Options. ` ` default_manager_name ` ¶
The name of the manager to use for the model’s [ ` _default_manager `
](../../../topics/db/managers/#django.db.models.Model._default_manager
"django.db.models.Model._default_manager") .
| |
Django_meta/django_models_7_0.txt | ## Model methods ¶
Define custom methods on a model to add custom “row-level” functionality to
your objects. Whereas [ ` Manager ` ](../managers/#django.db.models.Manager
"django.db.models.Manager") methods are intended to do “table-wide” things,
model methods should act on a particular model instance.
This is a v... | |
Django_meta/tutorialdjango_3_0.txt | * [   Download ](/Download) | |
Django_meta/tutorialdjango_189_0.txt | The following steps demonstrate creating a base template. | |
Django_meta/tutorialdjango_203_0.txt | 1. In VS Code, select the **File** (Windows/Linux) or **Code** (macOS), menu, then select **Preferences** > **User snippets** . | |
Django_meta/tutorialdjango_276_0.txt | {% if message_list %}
<table class="message_list">
<thead>
<tr>
<th>Date</th>
<th>Time</th>
<th>Message</th>
</tr>
</thead>
<tbody>
{% for message in message_list %}
<tr>
<td>{{ message.log_date | date:'d M Y' }}</td>
<td>{{ message.log_date | time:'H:i:s' }}</td>
<td>
{{ message.message }}
</td>
</tr>
{% endfor %}
</t... | |
Django_meta/introduction_55_0.txt | [ Chapter 1: Initial Set Up --> ](/initial-setup) | |
Django_meta/tutorialdjango_208_0.txt |
4. Save the ` html.json ` file ( ⌘S (Windows, Linux Ctrl+S ) ). | |
Django_meta/tutorialdjango_340_0.txt | * Hello from Seattle.
* [ Follow @code ](https://go.microsoft.com/fwlink/?LinkID=533687)
* | |
Django_meta/classbasedviews_25_0.txt | urlpatterns = [
path("about/", TemplateView.as_view(template_name="about.html")),
] | |
Django_meta/tutorialdjango_313_0.txt | > **Note** : ` pip freeze ` lists all the Python packages you have installed
> in the current environment, including packages you aren't currently using.
> The command also lists packages with exact version numbers, which you might
> want to convert to ranges for more flexibility in the future. For more
> information, ... | |
Django_meta/classbasedviews_35_0.txt | ### Supporting other HTTP methods ¶ | |
Django_meta/tutorialdjango_88_0.txt | {
// 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 Debugger: Django",
"type": "debugpy",
"request": "launch",
"program": "... | |
Django_meta/tutorialdjango_25_0.txt | In this section, you create a virtual environment in which Django is
installed. Using a virtual environment avoids installing Django into a global
Python environment and gives you exact control over the libraries used in an
application. A virtual environment also makes it easy to Create a
requirements.txt file for the... | |
Django_meta/introduction_51_0.txt | In the next chapter, you’ll learn how to properly set up your computer and
create your first Django project. Let’s begin! | |
Django_meta/tutorialdjango_190_0.txt | 1. In the ` templates/hello ` folder, create a file named ` layout.html ` with the contents below, which contains blocks named "title" and "content". As you can see, the markup defines a simple nav bar structure with links to Home, About, and Contact pages, which you create in a later section. Notice the use of Django'... | |
Django_meta/tutorialdjango_210_0.txt | For more information on code snippets in general, refer to [ Creating snippets
](/docs/editor/userdefinedsnippets) . | |
Django_meta/tutorialdjango_142_0.txt | A much better practice is to keep HTML out of your code entirely by using
**templates** , so that your code is concerned only with data values and not
with rendering. | |
Django_meta/introduction_14_0.txt | In contrast, some web frameworks like [ Flask
](https://flask.palletsprojects.com/en/2.2.x/) adopt a _microframework_
approach of providing only the bare minimum required for a simple webpage.
Flask is far more lightweight than Django and allows maximum flexibility;
however, this comes at a cost to the developer. Build... | |
Django_meta/tutorialdjango_297_0.txt | 1. In ` templates/hello/home.html ` , set breakpoints on both the ` {% if message_list %} ` and ` {% for message in message_list %} ` lines, as indicated by the yellow arrows in the image below: | |
Django_meta/introduction_17_0.txt | ## Why This Book | |
Django_meta/tutorialdjango_82_0.txt | ## Create a debugger launch profile | |
Django_meta/django_meta_21_0.txt | ### ` unique_together ` ¶
` Options. ` ` unique_together ` ¶
Use [ ` UniqueConstraint `
](../constraints/#django.db.models.UniqueConstraint
"django.db.models.UniqueConstraint") with the ` constraints ` option
instead.
[ ` UniqueConstraint ` ](../constraints/#django.db.models.UniqueConstraint
"django.db... | |
Django_meta/tutorialdjango_44_0.txt | python -m pip install django | |
Django_meta/introduction_36_0.txt | There are many code examples in this book, which are denoted as follows: | |
Django_meta/tutorialdjango_24_0.txt | ## Create a project environment for the Django tutorial | |
Django_meta/django_meta_6_0.txt | #### Table names ¶
To save you time, Django automatically derives the name of the database table
from the name of your model class and the app that contains it. A model’s
database table name is constructed by joining the model’s “app label” – the
name you used in [ ` manage.py startapp ` ](../../django-admin/#djan... | |
Django_meta/django_meta_19_0.txt | ### ` select_on_save ` ¶
` Options. ` ` select_on_save ` ¶
Determines if Django will use the pre-1.6 [ ` django.db.models.Model.save() `
](../instances/#django.db.models.Model.save "django.db.models.Model.save")
algorithm. The old algorithm uses ` SELECT ` to determine if there is an
existing row to be up... | |
Django_meta/classbasedviews_65_0.txt | [ FAQ ](https://docs.djangoproject.com/en/5.0/faq/) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.