I have installed grammar_check in a virtualenv and the I created a django project. Then in a my view I imported grammar_check and used it on some text but the issue is that I am getting import error. I don't understand what is the problem here.

Traceback (most recent call last):
  File "c:\users\saqib\appdata\local\programs\python\python36\Lib\threading.py",
 line 916, in _bootstrap_inner
    self.run()
  File "c:\users\saqib\appdata\local\programs\python\python36\Lib\threading.py",
 line 864, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\Saqib\Desktop\tbw\code\pro\lib\site-packages\django\utils\autor
eload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\Saqib\Desktop\tbw\code\pro\lib\site-packages\django\core\manage
ment\commands\runserver.py", line 117, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\Saqib\Desktop\tbw\code\pro\lib\site-packages\django\core\manage
ment\base.py", line 390, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Users\Saqib\Desktop\tbw\code\pro\lib\site-packages\django\core\manage
ment\base.py", line 377, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Users\Saqib\Desktop\tbw\code\pro\lib\site-packages\django\core\checks
\registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Users\Saqib\Desktop\tbw\code\pro\lib\site-packages\django\core\checks
\urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "C:\Users\Saqib\Desktop\tbw\code\pro\lib\site-packages\django\core\checks
\urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "C:\Users\Saqib\Desktop\tbw\code\pro\lib\site-packages\django\utils\funct
ional.py", line 80, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\Saqib\Desktop\tbw\code\pro\lib\site-packages\django\urls\resolv
ers.py", line 588, in url_patterns
    raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf 'gcpro.urls' d
oes 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.

Here is my view function:

from django.shortcuts import render
import grammar_check

# Create your views here.
def check(request):
    return render(request, 'home.html')

def output_text(request):
    if request.method == 'GET':
        name= request.GET.get('q')
        tool = grammar_check.LanguageTool('en-GB')
        texts = name
        matches = tool.check(texts)
        name = grammar_check.correct(texts,matches)
        return render(request, 'index.html', {'result': name})

EDIT: gcpro.urls

from django.conf.urls import url
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    path('checker/', include('checker.urls')),
]

checker.urls

# users/urls.py
from django.urls import path
from django.conf.urls import url
from . import views

urlpatterns = [
    path('check/', views.check, name='check'), 
    path('text/', views.output_text, name='outputtext'), 
]

This is the structure of project: project

  • checker
    • urls.py
    • views.py
    • and other files
  • gcpro
    • urls.py
    • settings.py
    • and other files
  • manage.py
  • db.sqlite3
  • templates
  • static

If this is not the way to import an external tool or I am doing any other thing the wrong way please let me know.

Thanks

1 Answers

0
thirteen3054 On

Ok so the issue was not related to any code but the error was occurring due to inconsistent spacing. I was using sublime and code appeared to be perfectly indented. But when I debugged the code step by step I found that there was an inconsistent space. Although I am not sure why it was giving an import error instead of an inconsistent space error.