Wednesday, May 20, 2020

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

如果您确定数据库中有数据的话,那么就是您该视图的url设计错误。Django数据库查询的get方法查询不到数据会报错。希望可以帮助到您。

ratnadeep ray <ratnadeep9@gmail.com> 于2020年5月20日周三 下午4:16写道:
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. 

--
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+unsubscribe@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.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHfGPEd6_f3W7fCiS-aSvkC5X%2BbTNRiUFXFTV_qjECAZyfGrNQ%40mail.gmail.com.

No comments:

Post a Comment