I am developing a website using Django framework. It works perfectly well using Django=True, however when I set Django=False, system could not find the other html files which are being accessed in <a href=... links. Let say, I am developing 'mysite', then the following code:
<li><a href="index-2.html"><i ></i></a></li>
is present behind an icon on mysite. Then clicking the icon takes the user to 'mysite.com/index-2.html', however it throws "The requested resource was not found on this server" error.
And this happens only when we set Django=False and in production. No link on the homepage is working due to this.
EDIT-1: I've already reviewed:
CodePudding user response:
try using onclick function instead of href and In static files you have add some configration to serve the static files in django.
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
#STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
# add manual
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
MEDIA_ROOT = os.path.join(BASE_DIR,'static/images/')
MESSAGE_TAGS = {
messages.ERROR: 'danger'
}
if this is work please contact me , I found this from freelance app
CodePudding user response:
To resolve this, I added specific functions for each of the .html files in views.py file and added link of the function to main html file. For example: I added following to my views.py file:
def about(request):
return render(request,'about.html')
and used as follows in index.html:
href = '\about'
Doing this for all used html files resolved the issue for both debug=True and debug=False. Not sure if this is the best way but working for now.