0

I have been trying to run a client-server application using Django. When I am trying to run my server in Django , it is giving me the following error.

django.core.exceptions.ImproperlyConfigured: The included URLconf '' 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.

The project urls.py -

from django.conf.urls import url,include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('chat.views')),
] 

App's views.py -

from django.shortcuts import render
from django.http import JsonResponse
def home(request):
if request.method == 'POST':

    if request.is_ajax():

       //code
        return JsonResponse(data)

return render(request,'index.html')

Where am I going wrong?

TeeKay
  • 1,025
  • 2
  • 22
  • 60

2 Answers2

5

include method takes app urls.py model not views.py. You need to create urls.py file inside your app and replace url(r'^', include('chat.views')) with url(r'^', include('chat.urls')) in projects urls file. See django docs.

neverwalkaloner
  • 46,181
  • 7
  • 92
  • 100
2

Include method in url.py file is used to include url patterns that are specified in other file. and when you are doing this url(r'^', include('chat.views')), it is unable to find url patterns in your views file. Hence giving error this:

django.core.exceptions.ImproperlyConfigured: The included URLconf '' 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.

we generally create a urls.py file in our app folder and write all our url patterns regarding this app in this file. create a new urls.py file in your app folder and write url patterns in that file.

and then include your app's urls.py file in main urls.py file like this:-

url(r'^', include('chat.urls')),

and your app's urls.py file should look like:

from django.conf.urls import url
urlpatterns = [
   url(r'', views.home, name = "home")),
] 

you can find out more about django urls from documentation:- django urls

And if you don't want to create new urls.py file in you app directory then you can just import your views in main urls.py file and write url pattern in this file. then your main urls.py file will look like this:-

from django.conf.urls import url,include
from django.contrib import admin
from chat.views import home

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^', home, name = "home"),
] 
Rohit Chopra
  • 567
  • 1
  • 8
  • 24