Getting the except django.core.exceptions.ImproperlyConfigured while querying DB

27 views
Skip to first unread message

ratnadeep ray

unread,
May 20, 2020, 4:15:58 AM5/20/20
to Django users
I am trying to fetch a few rows from the DB using the following code in my views.py:

from django.http import HttpResponse
from django.shortcuts import render
from fusioncharts.models import QRC_DB

def display_data(request,component):
    query_results = QRC_DB.objects.get(component_name__contains=component)
    return HttpResponse("You're looking at the component %s." % component)
For the above, I am getting the following exception:
django.core.exceptions.ImproperlyConfigured: The included URLconf 'Piechart_Excel.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.
However whenever I am removing/commenting out the below line, the above exception disappears:
query_results = QRC_DB.objects.get(component_name__contains=component)

Can anyone say what can be going wrong here?

urls.py file under app is as follows:

from django.urls import path from fusioncharts import views urlpatterns urlpatterns = [
path('push-data/', views.push_data, name='push-data'),
path('home/', views.home, name='home'),
path('display_data/<str:component>', views.display_data, name='display_data'),
]
The url under the main project is as follows: 
from django.contrib import admin from django.urls import path,include urlpatterns urlpatterns = [
path('admin/', admin.site.urls),
path('', include('fusioncharts.urls'))
]
So please advise what's going wrong. 

Hella Nick

unread,
May 20, 2020, 7:32:29 AM5/20/20
to django...@googlegroups.com
如果您确定数据库中有数据的话,那么就是您该视图的url设计错误。Django数据库查询的get方法查询不到数据会报错。希望可以帮助到您。

ratnadeep ray <ratna...@gmail.com> 于2020年5月20日周三 下午4:16写道:
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0acc7888-9e25-43fd-8a50-64fe43086190%40googlegroups.com.

Hella Nick

unread,
May 20, 2020, 7:35:03 AM5/20/20
to django...@googlegroups.com
此处有语法错误: path('display_data/<str:component>', views.display_data, name='display_data'),  
正确的写法为:path(r'^display_data/<str:component>/$', views.display_data, name='display_data/'),

请记住,一定要加 / 
Reply all
Reply to author
Forward
0 new messages