SyntaxError: invalid syntax with makemigrations

When Trying to perform:

python manage.py makemigrations, Im having this console output:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()
  File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/__init__.py", line 413, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 354, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 393, in execute
    self.check()
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 423, in check
    databases=databases,
  File "/usr/local/lib/python3.6/dist-packages/django/core/checks/registry.py", line 76, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/usr/local/lib/python3.6/dist-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "/usr/local/lib/python3.6/dist-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 602, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/usr/local/lib/python3.6/dist-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.6/dist-packages/django/urls/resolvers.py", line 595, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/jaodev/ftp/files/CallServiceBackEnd/callservices/urls.py", line 19, in <module>
    from callserviceapp.views import Buscar, addRubro, agregarFotoOrden, askPersonalInfo, cambiarEstadoOrden, chatMensaje, chatSinLeer, chatVer, completeInfo, completeInfoRubros, consultarOrdenParticular, consultarOrdenes, consultarTodasLasOrdenes, consultarTodasLasOrdenesCanceladas, consultarTodasLasOrdenesCurso, consultarTodasLasOrdenesFinalizadas, datosCliente, datosProveedor, deleteRubro, finalizarOrdenCliente, finalizarOrdenProveedor, homeCliente, homeClientePedirDatos, login, masInfoOrdenCliente, masInfoOrdenProveedor, modificarRubro, nuevaInfoPersonal, pedirOrdenEmergencia, pedirOrdenGeneral, presupuestoCliente, presupuestoProveedor, proveedorUbicacion,register, requestRubros, restarPassword, setNewPassword, verReseñas
  File "/home/jaodev/ftp/files/CallServiceBackEnd/callserviceapp/views.py", line 359
    de
     ^
SyntaxError: invalid syntax

At views.py, line 359, there is this function:

@csrf_exempt 
def nuevaInfoPersonal (request): 
    if request.method == 'POST':
        if(request.POST.get("tipo")=="1"):
            objetos=client.objects.filter(email=request.POST.get("email"))
            if not objetos:
                return HttpResponse("no ha sido posible")
            else: 
                email=objetos.first().email
                password=objetos.first().password
                objetos.first().delete()
                new=client()
                new.email=email
                new.password=password
                new.name=request.POST.get("nombre")
                new.last_name=request.POST.get("apellido")
                new.picture= request.FILES.get("image")
                new.qualification=request.POST.get("calificacion")
                new.save() 
                return HttpResponse("ok")

        if(request.POST.get("tipo")=="2"):
            objetos_=serviceProvider.objects.filter(email=request.POST.get("email"))
            
            if not objetos_:
                return HttpResponse("no ha sido posible")
            else: 
                email=objetos_.first().email
                password=objetos_.first().password
                objetos_.first().delete()
                new=serviceProvider()
                new.email=email
                new.password=password
                new.name=request.POST.get("nombre")
                new.last_name=request.POST.get("apellido")
                new.picture= request.FILES.get("image")
               # new.imagen_promocional= request.FILES.get("imagenPromocional")
                new.save() 
                return HttpResponse("ok")

        if(request.POST.get("tipo")=="3"):
            objetos=company.objects.filter(email=request.POST.get("email"))
           
            if not objetos:
                return HttpResponse("no ha sido posible")
            else: 
                email=objetos.first().email
                password=objetos.first().password
                objetos.first().delete()
                new=company()
                new.email=email
                new.password=password
                new.company_name=request.POST.get("nombre")
                new.company_description=request.POST.get("descripcion")
                new.picture= request.FILES.get("image")
               # new.imagen_promocional= request.FILES.get("imagenPromocional")
                new.save()
                return HttpResponse("ok")
    else: 
        return HttpResponse("bad")

But I can’t see what is wrong with it.

Is line 359 specifically this line?:

If so, we may need to see the function before this one in your views.py

1 Like

The line 359 is at:

def nuevaInfoPersonal (request)

That’s whay I was looking the problem there.

@csrf_exempt 
def completeInfo (request): 
    if request.method == 'POST': 
        if(request.POST.get("tipo")=="1"):
            objetos=client.objects.filter(email=request.POST.get("email"))
            if objetos:
                modelo=objetos.first()
                modelo.name=request.POST.get("nombre")
                modelo.last_name=request.POST.get("apellido")
                modelo.picture= request.FILES.get("image")
                modelo.qualification=0
                modelo.save()
                return HttpResponse("todo ok")
            else: 
                return HttpResponse("no usuario registrado")
        if(request.POST.get("tipo")=="2"):
            objetos=serviceProvider.objects.filter(email=request.POST.get("email"))            
            if objetos:
                modelo=objetos.first()
                modelo.name=request.POST.get("nombre")
                modelo.last_name=request.POST.get("apellido")
                modelo.picture= request.FILES.get("image")
               # modelo.imagen_promocional= request.FILES.get("imagenPromocional")
                modelo.qualification=0
                modelo.save()
                return HttpResponse("todo ok")
            else: 
                return HttpResponse("no usuario registrado")
        if(request.POST.get("tipo")=="3"):
            objetos=company.objects.filter(email=request.POST.get("email"))
            if objetos:
                modelo=objetos.first()
                modelo.company_name=request.POST.get("nombre")
                modelo.company_description=request.POST.get("descripcion")
                modelo.picture= request.FILES.get("image")
              #  modelo.imagen_promocional= request.FILES.get("imagenPromocional")
                modelo.qualification=0
                modelo.save()
                return HttpResponse("todo ok")
            else: 
                return HttpResponse("no usuario registrado")  
        else:
            return HttpResponse("no usuario registrado")

@csrf_exempt 
def nuevaInfoPersonal (request): 
    if request.method == 'POST':
        if(request.POST.get("tipo")=="1"):
            objetos=client.objects.filter(email=request.POST.get("email"))
            if not objetos:
                return HttpResponse("no ha sido posible")
            else: 
                email=objetos.first().email
                password=objetos.first().password
                objetos.first().delete()
                new=client()
                new.email=email
                new.password=password
                new.name=request.POST.get("nombre")
                new.last_name=request.POST.get("apellido")
                new.picture= request.FILES.get("image")
                new.qualification=request.POST.get("calificacion")
                new.save() 
                return HttpResponse("ok")

        if(request.POST.get("tipo")=="2"):
            objetos_=serviceProvider.objects.filter(email=request.POST.get("email"))
            
            if not objetos_:
                return HttpResponse("no ha sido posible")
            else: 
                email=objetos_.first().email
                password=objetos_.first().password
                objetos_.first().delete()
                new=serviceProvider()
                new.email=email
                new.password=password
                new.name=request.POST.get("nombre")
                new.last_name=request.POST.get("apellido")
                new.picture= request.FILES.get("image")
               # new.imagen_promocional= request.FILES.get("imagenPromocional")
                new.save() 
                return HttpResponse("ok")

        if(request.POST.get("tipo")=="3"):
            objetos=company.objects.filter(email=request.POST.get("email"))
           
            if not objetos:
                return HttpResponse("no ha sido posible")
            else: 
                email=objetos.first().email
                password=objetos.first().password
                objetos.first().delete()
                new=company()
                new.email=email
                new.password=password
                new.company_name=request.POST.get("nombre")
                new.company_description=request.POST.get("descripcion")
                new.picture= request.FILES.get("image")
               # new.imagen_promocional= request.FILES.get("imagenPromocional")
                new.save()
                return HttpResponse("ok")
    else: 
        return HttpResponse("bad")

I don’t see anything wrong.

What version of Django are you using? Django 4 requires at least Python 3.8. Django 3.2 is the last that supports Python 3.6

The only other thing I can think of is that there’s some non-visible character in your file in that location.

You could try viewing that file in an editor that would show you all characters, or you could copy/paste the text into a different file and try it.

1 Like

Django version: 3.2.11
Python version: 3.6.9

Problem solved! Thanks Ken. Filezilla did not sends the complete views.py file (I don’t know why but there was the problem)