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
2
Q
URL 3 components
A
- Url address (doesn’t really matter what it is)
- views.myfunc to take that in
- name = “” as a short cut (best practice)
because of 2, need to import views
from generator import views
3
Q
Media (Settings)
A
MEDIA_URL = '/anything/' MEDIA_ROOT = os.path.join(BASE_DIR, "media")
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)
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