Professional Documents
Culture Documents
urlpatterns = [
path("", views.home, name="home") // That name keyword attribute
is not specified in
Mosh Tutorial
]
6. In Mosh he placed the templates inside the app but here we have created a folder
called templates and static in the same folder where our main app and other apps are
and created a folder called calc (appname) and then placed the home.html file into that
calc ( Also in Documentation they have placed the templates, static folders inside each
apps and not as a common folder ). In views.py we have referred it as calc/home.html
and not as home.html (this also works) alone. In the same folder where our apps and
main project are . We need to do some changes to say django to look into that
templates because usually in looks for the templates folder whether it is inside the apps
and it wont check if the templates is outside the apps folder (as far as I know). Mostly
see Telusko Templates for path (might help)
2. For templates :
Import os
There will be a list called TEMPLATES in that type 'DIRS': [
os.path.join(BASE_DIR, "templates") ]
Here, after doing this command , django will took for templates folder not
only inside all the apps as it will do by default, but also from the root of our
project( BASR_DIR ) ( See telusko for more )
3. For static :
Scroll down till last type : STATICFILES_DIRS = [
os.path.join(BASE_DIR, "telusko/static") //“mainapp/foldername”
] // We can write many os.path. command to say django about the
location of static files to search for.
STATIC_ROOT = os.path.join(BASE_DIR, "assets")
Here , after doing this command, django will collect all the files in this static
folder and it will put them in a particular folder you specify ( assests in this
case ). But for that we need to say django to create a folder named assests.
This will collect all files inside static folder and put into assets ( in this
case ) folder
Example :
Change src=”images/destination.jpg as src="{% static
'images/destination_1.jpg' %}
By doing so we are saying the location where our images will be. It will be
pics folder (We specifies this pics folder in our Model) which is in media
folder . Not sure if the media folder is automatically created or I did
10. In urls.py of main project type :
10. For some validation like if the user name that the user has provided has already
been taken by someone else, we have inbuilt methods by which we can check
them.