Solucionado (ver solução)
Solucionado
(ver solução)
4
respostas

Problema ao alterar a mensagem inicial

Olá, minha aplicação está dando o seguinte erro:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f9fc8df5730>
Traceback (most recent call last):
  File "/usr/lib64/python3.4/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/usr/lib64/python3.4/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "/usr/lib64/python3.4/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/usr/lib64/python3.4/site-packages/django/core/management/base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "/usr/lib64/python3.4/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/usr/lib64/python3.4/site-packages/django/core/checks/urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "/usr/lib64/python3.4/site-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/usr/lib64/python3.4/site-packages/django/urls/resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "/usr/lib64/python3.4/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/lib64/python3.4/site-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/usr/lib64/python3.4/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/lib64/python3.4/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib64/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/batimin/Documentos/djanto-alura/connectedin/connectedin/urls.py", line 21, in <module>
    url(r'^$','perfis.views.index')
  File "/usr/lib64/python3.4/site-packages/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().

urls.py

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

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$','perfis.views.index')
]

views.py

from django.shortcuts import render
from django.http import HttpResponse

def index(request):
    return HttpResponse('Bem-vindo ao Connectedin')
4 respostas

O trecho de código exibido no urls.py é o mesmo do views.py. Poderia atualizar o post com o código correto?

Pronto, desculpe pelo erro.

solução!

Aqui o código que vc usou no connectedin.urls.py deu certo. Desconfio que seja problema de versão. Sua versão do Django é a requerida para o curso (1.7.x)?

Se não for, experimente corrigir o código de connectedin.urls.py para este:

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

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

A diferença deste código para o seu é que, ao invés de informar uma rota usando o caminho para view numa string, estamos passando (incluindo) a lista de urls do app perfis. Esse tipo de configuração, se não me engano, é a requerida nas versões mais novas do Django ( a partir da 1.10).

Funcionou, muito obrigado!