ImportError: No module named urls, Creating view in django

1

Good evening
I'm trying to create a view in Django and doing the runserver gives me the following error:

  

Performing system checks ...

     

Unhandled exception in thread started by Traceback (most recent call last): File   "C: \ Python27 \ lib \ site-packages \ django-1.10.6-py2.7.egg \ django \ utils \ autoreload.py",   line 226, in wrapper       fn (* args, ** kwargs) File "C: \ Python27 \ lib \ site-packages \ django-1.10.6-py2.7.egg \ django \ core \ management \ commands \ runserver.py",   line 121, in inner_run       self.check (display_num_errors = True) File "C: \ Python27 \ lib \ site-packages \ django-1.10.6-py2.7.egg \ django \ core \ management \ base.py",   line 374, in check       include_deployment_checks = include_deployment_checks, File "C: \ Python27 \ lib \ site-packages \ django-1.10.6-py2.7.egg \ django \ core \ management \ base.py",   line 361, in _run_checks       return checks.run_checks (** kwargs) File "C: \ Python27 \ lib \ site-packages \ django-1.10.6-py2.7.egg \ django \ core \ checks \ registry.py",   line 81, in run_checks       new_errors = check (app_configs = app_configs) File "C: \ Python27 \ lib \ site-packages \ django-1.10.6-py2.7.egg \ django \ core \ checks \ urls.py",   line 14, in check_url_config       return check_resolve (resolve) File "C: \ Python27 \ lib \ site-packages \ django-1.10.6-py2.7.egg \ django \ core \ checks \ urls.py",   line 24, in check_resolver       for pattern in resolver.url_patterns: File "C: \ Python27 \ lib \ site-packages \ django-1.10.6-py2.7.egg \ django \ utils \ functional.py",   line 35, in get       res = instance. dict [self.name] = self.func (instance) File "C: \ Python27 \ lib \ site-packages \ django-1.10.6-py2.7.egg \ django \ urls \ resolvers.py ",   line 313, in url_patterns       patterns = getattr (self.urlconf_module, "urlpatterns", self.urlconf_module) File   "C: \ Python27 \ lib \ site-packages \ django-1.10.6-py2.7.egg \ django \ utils \ functional.py",   line 35, in get       res = instance. dict [self.name] = self.func (instance) File "C: \ Python27 \ lib \ site-packages \ django-1.10.6-py2.7.egg \ django \ urls \ resolvers.py ",   line 306, in urlconf_module       return import_module (self.urlconf_name) File "C: \ Python27 \ lib \ importlib__init __. py", line 37, in import_module        import (name) File "C: \ Users \ Manux \ Desktop \ probardjango \ src \ pdj \ urls.py", line 21, in          url (r '', 'boletin.views.incio', name = 'home'), File "C: \ Python27 \ lib \ site-packages \ django-1.10.6-py2.7.egg \ django \ conf \ urls__init__.py ",   line 85, in url       raise TypeError ('view must be a callable or a list / tuple in the case of include ().') TypeError: view must be a callable or a   list / tuple in the case of include ().

'views.py':

from django.shortcuts import render

# Create your views here.

def inicio(request):
return render(request, "inicio.html", {})

'urls.py':

 from django.conf.urls import url
 from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'', 'boletin.views.incio', name='inicio'),
]

'settings.py':

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'boletin',
]
ROOT_URLCONF = 'pdj.urls'
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, "templates")],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

Structure:

I hope you can help me, thanks in advance and greetings.

    
asked by manuxdjent 18.03.2017 в 00:04
source

2 answers

1

How about, I see

You will see, django 1.10 what is the one you are using does not allow to do this.

 url(r'', 'boletin.views.incio', name='inicio'),

in previous versions was the way to make the imports of the urls, now the correct way would be:

If you want to do the direct import in the urls.py of your project it should look like this:

from django.conf.urls import url
from django.contrib import admin
from boletin.views import inicio

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'', inicio, name='inicio'),
]
    
answered by 18.03.2017 / 01:05
source
0

It seems that you need to create the urls.py file inside your newsletter application.

As I see, on line 22 of the urls.py of your project, you are doing one:

url(r'', include('boletin.urls'))

Which leads Django to look for that file that does not exist.

    
answered by 18.03.2017 в 00:52