0
votes

I'm getting this error while using django 1.10.6:

ValueError at /AgregarTienda The view chilegaleria.views.AgregarTienda_View didn't return an HttpResponse object. It returned None instead.

This is my view

from django.shortcuts import render
from django.http import HttpResponse
from chilegaleria.forms import AgregarTiendaForm
# Create your views here.
def index(request):
    return render(request, 'chilegaleria/index.html')
def AgregarTienda_View(request):
    if request.method == 'POST':
        form = AgregarTiendaForm(request.POST)
    if form.is_valid():
            form.save()
            return redirect('chilegaleria:index')
    else:
            form = AgregarTiendaForm
            return render(request, 'chilegaleria/AgregarTienda.html', {'form':form})

Also when I add class Meta: model = DatosTienda to my forms.py file I get this error:

C:\chilegalerias>manage.py check Traceback (most recent call last): File "C:\chilegalerias\manage.py", line 22, in execute_from_command_line(sys.argv) File "C:\Python27\lib\site-packages\django-1.10.6-py2.7.egg\django\core\management__init__.py", line 367, in execute_from_command_line utility.execute() File "C:\Python27\lib\site-packages\django-1.10.6-py2.7.egg\django\core\management__init__.py", line 359, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\Python27\lib\site-packages\django-1.10.6-py2.7.egg\django\core\management\base.py", line 294, in run_from_argv self.execute(*args, **cmd_options) File "C:\Python27\lib\site-packages\django-1.10.6-py2.7.egg\django\core\management\base.py", line 345, in execute output = self.handle(*args, **options) File "C:\Python27\lib\site-packages\django-1.10.6-py2.7.egg\django\core\management\commands\check.py", line 68, in handle fail_level=getattr(checks, options['fail_level']), 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_resolver(resolver) 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:\chilegalerias\chilegalerias\urls.py", line 21, in url(r'^', include ('chilegaleria.urls')), File "C:\Python27\lib\site-packages\django-1.10.6-py2.7.egg\django\conf\urls__init__.py", line 50, in include urlconf_module = import_module(urlconf_module) File "C:\Python27\lib\importlib__init__.py", line 37, in import_module import(name) File "C:\chilegalerias\chilegaleria\urls.py", line 3, in from chilegaleria.views import index, AgregarTienda_View File "C:\chilegalerias\chilegaleria\views.py", line 3, in from chilegaleria.forms import AgregarTiendaForm File "C:\chilegalerias\chilegaleria\forms.py", line 4, in class AgregarTiendaForm(forms.ModelForm): File "C:\chilegalerias\chilegaleria\forms.py", line 7, in AgregarTiendaForm class Meta: File "C:\chilegalerias\chilegaleria\forms.py", line 8, in Meta Model = DatosTienda NameError: name 'DatosTienda' is not defined

This is my forms.py file:

from django import forms
from chilegaleria.models import models
from django.forms import ModelForm
class AgregarTiendaForm(forms.ModelForm):


    class Meta:
        model = DatosTienda
        fields = [
        'nombre',
        'estado',
        'ciudad',
        'comuna',
        'direccion',
        ]
        labels = {
        'nombre': 'Nombre de la Tienda',
        'estado': 'Region',
        'ciudad': 'Ciudad',
        'comuna': 'Comuna',
        'direccion': 'Direccion',
        }
        widgets = {
        'nombre': forms.TextInput(attrs={'class':'form-control'}),
        'estado': forms.TextInput(attrs={'class':'form-control'}),
        'ciudad': forms.TextInput(attrs={'class':'form-control'}),
        'comuna': forms.TextInput(attrs={'class':'form-control'}),
        'direccion': forms.TextInput(attrs={'class':'form-control'}),
        }
1

1 Answers

0
votes

File "C:\chilegalerias\chilegaleria\forms.py", line 8, in Meta Model = DatosTienda NameError: name 'DatosTienda' is not defined

Your log stack says that you must import the model DatosTienda in the file chilegaleria\forms.py

Also check your view, because if you get a GET request, your form is not being defined, so you will get a referenced before assignment an error.