I am new to Django and hence don't have much idea about it. I am trying to create an app having the following contents in my view.py file:
from django.shortcuts import render
from fusioncharts.models import City
def pie_chart(request):
labels = []
data = []
queryset = City.objects.order_by('-population')[:3]
for city in queryset:
labels.append(city.name)
data.append(city.population)
return render(request, 'pie_chart.html', {
'labels': labels,
'data': data,
})
The content of my urls.py file inside the app is as follows:
from django.urls import path
from fusioncharts import views
urlpatterns = [
path('pie-chart/', views.pie_chart, name='pie-chart'),
]
and the content of my urls.py file inside the main project folder is as follows:
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('fusioncharts.urls'))
]
In the settings.py file, I have added the following:
ROOT_URLCONF = 'Piechart.urls'
and under the TEMPLATES, added the following:
'DIRS': ['Piechart/fusioncharts/templates'],
Now while running my app, I am getting the following error:
django.core.exceptions.ImproperlyConfigured: The included URLconf 'Piechart.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
Can anyone please say what's going wrong?
you forgot to import include in the project urls.py, i was about to comment this but can't in my current reputation level.
from django.urls import path,include
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.