-1

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 class="fab fa-dribbble"></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:

Why does DEBUG=False setting make my django Static Files Access fail?

The static files are already working fine on my app because they are in 'assets' folder. The html files are in the root folder and somehow system is not able to find any file from root folder when debug is set to False. So my question is more regarding finding files at root folder using href links.

No error for files in 'assets' folder, but 404 for root folder files:

enter image description here

AbhiGupta
  • 474
  • 1
  • 6
  • 14
  • 1
    Does this answer your question? [Why does DEBUG=False setting make my django Static Files Access fail?](https://stackoverflow.com/questions/5836674/why-does-debug-false-setting-make-my-django-static-files-access-fail) – Abdul Aziz Barkat Aug 30 '22 at 15:24
  • Already viewed this. It doesn't, static files are working fine, just the html links are not working. Links are working but not finding the files at the root. Maybe something related to views. – AbhiGupta Aug 30 '22 at 15:26
  • @AbhiGupta: likely the static ones are due to caching, since, well, these are static... – Willem Van Onsem Aug 30 '22 at 15:59
  • The images, icons and other files are being updated fine which suggests they are not due to caching. It's just html files which are throwing 404. – AbhiGupta Aug 31 '22 at 01:54

2 Answers2

1

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

Naman Garg
  • 53
  • 4
  • I already have same settings for static files and onclick didn't do anything. Thanks for your response. – AbhiGupta Aug 31 '22 at 16:32
0

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.

AbhiGupta
  • 474
  • 1
  • 6
  • 14