Setting & URLs Flashcards

1
Q

URLs.py

A

from myapps import views

path(‘’, views.home)
empty path mean default home

path(‘doesntmatter/’, views.password, name=’passwordtest’),
*path name will be shown in url, views is the actual page, name is a reference for forms

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

URL 3 components

A
  1. Url address (doesn’t really matter what it is)
  2. views.myfunc to take that in
  3. name = “” as a short cut (best practice)

because of 2, need to import views
from generator import views

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Media (Settings)

A
MEDIA_URL = '/anything/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Media (URL)

A

from django.conf.urls.static import static
from django.conf import settings

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

forward (include) URL to apps

A

from django.urls import path, include

path(‘blog/’, include(‘blog.urls’)),

  • need to recreate the urls.py file in an app
How well did you know this?
1
Not at all
2
3
4
5
Perfectly