Template doesn't exist
I'm new to django. I am trying to learn it by building a project. I wanna replace the django's localhost hompage with my homepage. But, I couldn't find views.py in main project directory.Why? By the way, I made a new 'views.py' and also created a templates folder and put index.html in another directory inside templates named englishexchange. Below is the project structure.
englishexchange/ manage.py and exnglishexchange/ views.py,urls.py and templates/englishexchange/index.html
englishexchange/url.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name = 'index'),
path('admin/', admin.site.urls),
]
englishexchange/views.py
from django.shortcuts import render
def index(request):
return render(request, 'englishexchange/index.html')
and I put my templates directory in main project directory englishexchange.
I know I can do that by making another app and maping the url to nothing like ' '. But I want them to have different home page than the main's static home page.
The error I am getting is like
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.app_directories.Loader: C:UsersSujeet AgrahariAppDataLocalProgramsPythonPython37-32libsite-packagesdjangocontribadmintemplatesenglishexchangeindex.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:UsersSujeet AgrahariAppDataLocalProgramsPythonPython37-32libsite-packagesdjangocontribauthtemplatesenglishexchangeindex.html (Source does not exist)
I believe it's trying to find the templates in its default directory which is admin. How can I change this behavior so that it gets the templates from mian project directory?
django
add a comment |
I'm new to django. I am trying to learn it by building a project. I wanna replace the django's localhost hompage with my homepage. But, I couldn't find views.py in main project directory.Why? By the way, I made a new 'views.py' and also created a templates folder and put index.html in another directory inside templates named englishexchange. Below is the project structure.
englishexchange/ manage.py and exnglishexchange/ views.py,urls.py and templates/englishexchange/index.html
englishexchange/url.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name = 'index'),
path('admin/', admin.site.urls),
]
englishexchange/views.py
from django.shortcuts import render
def index(request):
return render(request, 'englishexchange/index.html')
and I put my templates directory in main project directory englishexchange.
I know I can do that by making another app and maping the url to nothing like ' '. But I want them to have different home page than the main's static home page.
The error I am getting is like
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.app_directories.Loader: C:UsersSujeet AgrahariAppDataLocalProgramsPythonPython37-32libsite-packagesdjangocontribadmintemplatesenglishexchangeindex.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:UsersSujeet AgrahariAppDataLocalProgramsPythonPython37-32libsite-packagesdjangocontribauthtemplatesenglishexchangeindex.html (Source does not exist)
I believe it's trying to find the templates in its default directory which is admin. How can I change this behavior so that it gets the templates from mian project directory?
django
add a comment |
I'm new to django. I am trying to learn it by building a project. I wanna replace the django's localhost hompage with my homepage. But, I couldn't find views.py in main project directory.Why? By the way, I made a new 'views.py' and also created a templates folder and put index.html in another directory inside templates named englishexchange. Below is the project structure.
englishexchange/ manage.py and exnglishexchange/ views.py,urls.py and templates/englishexchange/index.html
englishexchange/url.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name = 'index'),
path('admin/', admin.site.urls),
]
englishexchange/views.py
from django.shortcuts import render
def index(request):
return render(request, 'englishexchange/index.html')
and I put my templates directory in main project directory englishexchange.
I know I can do that by making another app and maping the url to nothing like ' '. But I want them to have different home page than the main's static home page.
The error I am getting is like
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.app_directories.Loader: C:UsersSujeet AgrahariAppDataLocalProgramsPythonPython37-32libsite-packagesdjangocontribadmintemplatesenglishexchangeindex.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:UsersSujeet AgrahariAppDataLocalProgramsPythonPython37-32libsite-packagesdjangocontribauthtemplatesenglishexchangeindex.html (Source does not exist)
I believe it's trying to find the templates in its default directory which is admin. How can I change this behavior so that it gets the templates from mian project directory?
django
I'm new to django. I am trying to learn it by building a project. I wanna replace the django's localhost hompage with my homepage. But, I couldn't find views.py in main project directory.Why? By the way, I made a new 'views.py' and also created a templates folder and put index.html in another directory inside templates named englishexchange. Below is the project structure.
englishexchange/ manage.py and exnglishexchange/ views.py,urls.py and templates/englishexchange/index.html
englishexchange/url.py
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name = 'index'),
path('admin/', admin.site.urls),
]
englishexchange/views.py
from django.shortcuts import render
def index(request):
return render(request, 'englishexchange/index.html')
and I put my templates directory in main project directory englishexchange.
I know I can do that by making another app and maping the url to nothing like ' '. But I want them to have different home page than the main's static home page.
The error I am getting is like
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.app_directories.Loader: C:UsersSujeet AgrahariAppDataLocalProgramsPythonPython37-32libsite-packagesdjangocontribadmintemplatesenglishexchangeindex.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:UsersSujeet AgrahariAppDataLocalProgramsPythonPython37-32libsite-packagesdjangocontribauthtemplatesenglishexchangeindex.html (Source does not exist)
I believe it's trying to find the templates in its default directory which is admin. How can I change this behavior so that it gets the templates from mian project directory?
django
django
edited Nov 22 '18 at 13:38
Sujeet Agrahari
asked Nov 22 '18 at 13:19
Sujeet AgrahariSujeet Agrahari
365
365
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
But, I couldn't find views.py in main project directory.Why?
Django encourages you to make apps for almost anything you do. So there is no views.py in the main project directory.
Regarding template rendering be sure to add:
os.path.join(BASE_DIR,'templates')
in 'DIR' as stated in an answer above.
add a comment |
Make sure your views.py file is inside the app folder you made , and templates folder inside the project folder not your app folder , for changing current home page , just add
path('home/', views.index , name = 'index'),
You can replace home with any thing you want your home page url to be.
If there is another folder inside template directory for ex.xyz
i.e the file location becometemplates/xyz/index.html
, you shouldreturn render(request , 'xyz/index.html')
– Jidnyesh
Nov 22 '18 at 13:36
I haven't made an app yet. It's the main project directory. englishexchange/ manage.py and exnglishexchange/ views.py,urls.py and templates/englishexchange/index.html
– Sujeet Agrahari
Nov 22 '18 at 13:36
First of all , if u havent made an app , views.py wont appear. Make a app typingpython manage.py startapp englishexchange
in terminal in project directory
– Jidnyesh
Nov 22 '18 at 13:42
all the files like views.py , models.py will automatically appear in the app folder and you dont have to make them manually
– Jidnyesh
Nov 22 '18 at 13:43
As I mentioned I can do that but that way every app will have its own home page, I just want a static homepage for the main project and separate homepage for each app if required.
– Sujeet Agrahari
Nov 22 '18 at 13:48
|
show 1 more comment
Make sure to add this in your settings file
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
where you can change the 'templates' in DIRS
to any folder you want to keep your template files to.
Rather than making two answers, you should delete this one and append the content of this answer to your other answer. :)
– ruddra
Nov 22 '18 at 13:48
I did those changes in DIRS, but that way I can only change the last directory in which it's looking for index.html. That doesn't change the base directory.
– Sujeet Agrahari
Nov 22 '18 at 13:49
@ruddra , you are a certified django developer , can you tell me the source you learnt django
– Jidnyesh
Nov 22 '18 at 14:03
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431912%2ftemplate-doesnt-exist%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
But, I couldn't find views.py in main project directory.Why?
Django encourages you to make apps for almost anything you do. So there is no views.py in the main project directory.
Regarding template rendering be sure to add:
os.path.join(BASE_DIR,'templates')
in 'DIR' as stated in an answer above.
add a comment |
But, I couldn't find views.py in main project directory.Why?
Django encourages you to make apps for almost anything you do. So there is no views.py in the main project directory.
Regarding template rendering be sure to add:
os.path.join(BASE_DIR,'templates')
in 'DIR' as stated in an answer above.
add a comment |
But, I couldn't find views.py in main project directory.Why?
Django encourages you to make apps for almost anything you do. So there is no views.py in the main project directory.
Regarding template rendering be sure to add:
os.path.join(BASE_DIR,'templates')
in 'DIR' as stated in an answer above.
But, I couldn't find views.py in main project directory.Why?
Django encourages you to make apps for almost anything you do. So there is no views.py in the main project directory.
Regarding template rendering be sure to add:
os.path.join(BASE_DIR,'templates')
in 'DIR' as stated in an answer above.
answered Nov 22 '18 at 13:55
theredcaptheredcap
296
296
add a comment |
add a comment |
Make sure your views.py file is inside the app folder you made , and templates folder inside the project folder not your app folder , for changing current home page , just add
path('home/', views.index , name = 'index'),
You can replace home with any thing you want your home page url to be.
If there is another folder inside template directory for ex.xyz
i.e the file location becometemplates/xyz/index.html
, you shouldreturn render(request , 'xyz/index.html')
– Jidnyesh
Nov 22 '18 at 13:36
I haven't made an app yet. It's the main project directory. englishexchange/ manage.py and exnglishexchange/ views.py,urls.py and templates/englishexchange/index.html
– Sujeet Agrahari
Nov 22 '18 at 13:36
First of all , if u havent made an app , views.py wont appear. Make a app typingpython manage.py startapp englishexchange
in terminal in project directory
– Jidnyesh
Nov 22 '18 at 13:42
all the files like views.py , models.py will automatically appear in the app folder and you dont have to make them manually
– Jidnyesh
Nov 22 '18 at 13:43
As I mentioned I can do that but that way every app will have its own home page, I just want a static homepage for the main project and separate homepage for each app if required.
– Sujeet Agrahari
Nov 22 '18 at 13:48
|
show 1 more comment
Make sure your views.py file is inside the app folder you made , and templates folder inside the project folder not your app folder , for changing current home page , just add
path('home/', views.index , name = 'index'),
You can replace home with any thing you want your home page url to be.
If there is another folder inside template directory for ex.xyz
i.e the file location becometemplates/xyz/index.html
, you shouldreturn render(request , 'xyz/index.html')
– Jidnyesh
Nov 22 '18 at 13:36
I haven't made an app yet. It's the main project directory. englishexchange/ manage.py and exnglishexchange/ views.py,urls.py and templates/englishexchange/index.html
– Sujeet Agrahari
Nov 22 '18 at 13:36
First of all , if u havent made an app , views.py wont appear. Make a app typingpython manage.py startapp englishexchange
in terminal in project directory
– Jidnyesh
Nov 22 '18 at 13:42
all the files like views.py , models.py will automatically appear in the app folder and you dont have to make them manually
– Jidnyesh
Nov 22 '18 at 13:43
As I mentioned I can do that but that way every app will have its own home page, I just want a static homepage for the main project and separate homepage for each app if required.
– Sujeet Agrahari
Nov 22 '18 at 13:48
|
show 1 more comment
Make sure your views.py file is inside the app folder you made , and templates folder inside the project folder not your app folder , for changing current home page , just add
path('home/', views.index , name = 'index'),
You can replace home with any thing you want your home page url to be.
Make sure your views.py file is inside the app folder you made , and templates folder inside the project folder not your app folder , for changing current home page , just add
path('home/', views.index , name = 'index'),
You can replace home with any thing you want your home page url to be.
answered Nov 22 '18 at 13:33
JidnyeshJidnyesh
75
75
If there is another folder inside template directory for ex.xyz
i.e the file location becometemplates/xyz/index.html
, you shouldreturn render(request , 'xyz/index.html')
– Jidnyesh
Nov 22 '18 at 13:36
I haven't made an app yet. It's the main project directory. englishexchange/ manage.py and exnglishexchange/ views.py,urls.py and templates/englishexchange/index.html
– Sujeet Agrahari
Nov 22 '18 at 13:36
First of all , if u havent made an app , views.py wont appear. Make a app typingpython manage.py startapp englishexchange
in terminal in project directory
– Jidnyesh
Nov 22 '18 at 13:42
all the files like views.py , models.py will automatically appear in the app folder and you dont have to make them manually
– Jidnyesh
Nov 22 '18 at 13:43
As I mentioned I can do that but that way every app will have its own home page, I just want a static homepage for the main project and separate homepage for each app if required.
– Sujeet Agrahari
Nov 22 '18 at 13:48
|
show 1 more comment
If there is another folder inside template directory for ex.xyz
i.e the file location becometemplates/xyz/index.html
, you shouldreturn render(request , 'xyz/index.html')
– Jidnyesh
Nov 22 '18 at 13:36
I haven't made an app yet. It's the main project directory. englishexchange/ manage.py and exnglishexchange/ views.py,urls.py and templates/englishexchange/index.html
– Sujeet Agrahari
Nov 22 '18 at 13:36
First of all , if u havent made an app , views.py wont appear. Make a app typingpython manage.py startapp englishexchange
in terminal in project directory
– Jidnyesh
Nov 22 '18 at 13:42
all the files like views.py , models.py will automatically appear in the app folder and you dont have to make them manually
– Jidnyesh
Nov 22 '18 at 13:43
As I mentioned I can do that but that way every app will have its own home page, I just want a static homepage for the main project and separate homepage for each app if required.
– Sujeet Agrahari
Nov 22 '18 at 13:48
If there is another folder inside template directory for ex.
xyz
i.e the file location become templates/xyz/index.html
, you should return render(request , 'xyz/index.html')
– Jidnyesh
Nov 22 '18 at 13:36
If there is another folder inside template directory for ex.
xyz
i.e the file location become templates/xyz/index.html
, you should return render(request , 'xyz/index.html')
– Jidnyesh
Nov 22 '18 at 13:36
I haven't made an app yet. It's the main project directory. englishexchange/ manage.py and exnglishexchange/ views.py,urls.py and templates/englishexchange/index.html
– Sujeet Agrahari
Nov 22 '18 at 13:36
I haven't made an app yet. It's the main project directory. englishexchange/ manage.py and exnglishexchange/ views.py,urls.py and templates/englishexchange/index.html
– Sujeet Agrahari
Nov 22 '18 at 13:36
First of all , if u havent made an app , views.py wont appear. Make a app typing
python manage.py startapp englishexchange
in terminal in project directory– Jidnyesh
Nov 22 '18 at 13:42
First of all , if u havent made an app , views.py wont appear. Make a app typing
python manage.py startapp englishexchange
in terminal in project directory– Jidnyesh
Nov 22 '18 at 13:42
all the files like views.py , models.py will automatically appear in the app folder and you dont have to make them manually
– Jidnyesh
Nov 22 '18 at 13:43
all the files like views.py , models.py will automatically appear in the app folder and you dont have to make them manually
– Jidnyesh
Nov 22 '18 at 13:43
As I mentioned I can do that but that way every app will have its own home page, I just want a static homepage for the main project and separate homepage for each app if required.
– Sujeet Agrahari
Nov 22 '18 at 13:48
As I mentioned I can do that but that way every app will have its own home page, I just want a static homepage for the main project and separate homepage for each app if required.
– Sujeet Agrahari
Nov 22 '18 at 13:48
|
show 1 more comment
Make sure to add this in your settings file
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
where you can change the 'templates' in DIRS
to any folder you want to keep your template files to.
Rather than making two answers, you should delete this one and append the content of this answer to your other answer. :)
– ruddra
Nov 22 '18 at 13:48
I did those changes in DIRS, but that way I can only change the last directory in which it's looking for index.html. That doesn't change the base directory.
– Sujeet Agrahari
Nov 22 '18 at 13:49
@ruddra , you are a certified django developer , can you tell me the source you learnt django
– Jidnyesh
Nov 22 '18 at 14:03
add a comment |
Make sure to add this in your settings file
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
where you can change the 'templates' in DIRS
to any folder you want to keep your template files to.
Rather than making two answers, you should delete this one and append the content of this answer to your other answer. :)
– ruddra
Nov 22 '18 at 13:48
I did those changes in DIRS, but that way I can only change the last directory in which it's looking for index.html. That doesn't change the base directory.
– Sujeet Agrahari
Nov 22 '18 at 13:49
@ruddra , you are a certified django developer , can you tell me the source you learnt django
– Jidnyesh
Nov 22 '18 at 14:03
add a comment |
Make sure to add this in your settings file
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
where you can change the 'templates' in DIRS
to any folder you want to keep your template files to.
Make sure to add this in your settings file
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
where you can change the 'templates' in DIRS
to any folder you want to keep your template files to.
answered Nov 22 '18 at 13:41
JidnyeshJidnyesh
75
75
Rather than making two answers, you should delete this one and append the content of this answer to your other answer. :)
– ruddra
Nov 22 '18 at 13:48
I did those changes in DIRS, but that way I can only change the last directory in which it's looking for index.html. That doesn't change the base directory.
– Sujeet Agrahari
Nov 22 '18 at 13:49
@ruddra , you are a certified django developer , can you tell me the source you learnt django
– Jidnyesh
Nov 22 '18 at 14:03
add a comment |
Rather than making two answers, you should delete this one and append the content of this answer to your other answer. :)
– ruddra
Nov 22 '18 at 13:48
I did those changes in DIRS, but that way I can only change the last directory in which it's looking for index.html. That doesn't change the base directory.
– Sujeet Agrahari
Nov 22 '18 at 13:49
@ruddra , you are a certified django developer , can you tell me the source you learnt django
– Jidnyesh
Nov 22 '18 at 14:03
Rather than making two answers, you should delete this one and append the content of this answer to your other answer. :)
– ruddra
Nov 22 '18 at 13:48
Rather than making two answers, you should delete this one and append the content of this answer to your other answer. :)
– ruddra
Nov 22 '18 at 13:48
I did those changes in DIRS, but that way I can only change the last directory in which it's looking for index.html. That doesn't change the base directory.
– Sujeet Agrahari
Nov 22 '18 at 13:49
I did those changes in DIRS, but that way I can only change the last directory in which it's looking for index.html. That doesn't change the base directory.
– Sujeet Agrahari
Nov 22 '18 at 13:49
@ruddra , you are a certified django developer , can you tell me the source you learnt django
– Jidnyesh
Nov 22 '18 at 14:03
@ruddra , you are a certified django developer , can you tell me the source you learnt django
– Jidnyesh
Nov 22 '18 at 14:03
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431912%2ftemplate-doesnt-exist%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown