Updated, Please check the updated part.
I am trying to deploy a Django Application on Render.
In my project, I have some number of apps that have their own urls.py
file. Then, in the project's url, I included them. Have a look at the project's url:
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('home.urls')),
path('about/', include('about.urls')),
path('kbdash/', include('management.urls')),
]
And for every app the url looks like this:
urlpatterns = [
path('', about_page, name='about'),
]
all these urls work except for the path('kbdash/', include('management.urls'))
Below is the url of management app:
urlpatterns = [
path('', views.Dashboard.as_view(), name='dashboard'),
path('fuels/', views.fuel_list_view, name='fuel_list'),
]
all the urls in main urls file are working except for the kbdash/
Visiting kbdash/
and any link under kbdash/
throw Server Error (500)
View associated with /kbdash/
url. :
class Dashboard(LoginRequiredMixin, generic.View):
def get(self, request, *args, **kwargs):
fuels = Fuel.objects.filter(status=1)
try:
total_sale = Sale.objects.filter(fuel__id__in = fuels).aggregate(Sum('total_amount'))['total_amount__sum']
if total_sale is None:
total_sale = 0
except:
total_sale = 0
context = {
'total_fuel_count': fuels.count(),
'fuels': fuels,
'total_sale': total_sale,
}
return render(request, 'management/dashboard.html', context)
I tried changing DEBUG to True in production to see error in browser. Doing so the url is working. But it should work even when the DEBUG is False.
I have no idea why such behaviour. On local computer it's working perfectly.
Can somebody guide me into the light...!
Updated part:
I used the ADMINS
setting in settings.py
. Now I got the error in my gmail inbox.
The error:
Internal Server Error: /kbdash/
ValueError at /kbdash/ Missing staticfiles manifest entry for 'select2/dist/css/select2.min.css' Request Method: GET Request URL: https://kb-cng-web.onrender.com/kbdash/
I used select2 for select element. It's perfectly working locally. but in the production it's not available in staticfiles.
I also tried the source code but checking the url /static/path/to/select2
shows that It's not available in production.
What might be a way to trace it?
Base.html
https://jsfiddle.net/8ozt2761/
Dashboard.html
I just solved it.
I stored the select2 source code in the a select2 folder like this:
select2/dist/css/select2.min.css
select2/dist/js/select2.min.js
So when running the collectstatic in production it didn't find the sources in the path.
Then after so many debugging I changed the path and directly placed the min.css and min.js under select2 folder.
Now after running collectstatic it finds the path of select2.