UnboundLocalError: local variable referenced before assignment
Publicado por Miguel (1 intervención) el 11/02/2018 22:50:05
I'm Having some troubles with thse
The Output Shell is this
Can someone help me please
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def inicio(request):
meses = {'01':"Enero", '02':"Febrero", '03':"Marzo", '04':"Abril", '05':"Mayo",'06':"Junio",
'07' : "Julio", '08':"Agosto", '09':"Septiembre",'10':"Octubre",'11':"Noviembre",
'12':"Diciembre"}
objq1 = Clients.objects.raw('SELECT DISTINCT Id_Compra,MONTH(Fecha) as DateF FROM `HypermedialAPP_clients` WHERE Medio = "Facebook"')
for bce in objq1 :
objq1Date = bce.DateF
for ced in Clients.objects.raw('SELECT DISTINCT Id_Compra,COUNT(*) as MaxFB FROM `HypermedialAPP_clients` WHERE Medio = "Facebook" and MONTH(Fecha) = %s GROUP BY Id_Compra', [bce.DateF]):
obj_FBc = ced.MaxFB
objq2 = Clients.objects.raw('SELECT DISTINCT Id_Compra,MONTH(Fecha) as DateF FROM `HypermedialAPP_clients` WHERE Medio = "WhatsApp"')
for edf in objq2:
objq2Date = edf.DateF
for dfg in Clients.objects.raw('SELECT DISTINCT Id_Compra,COUNT(*)as MaxsWP FROM `HypermedialAPP_clients` WHERE Medio = "WhatsApp" and MONTH(Fecha) = %s GROUP BY Id_Compra', [edf.DateF]):
obj_WPc = dfg.MaxsWP
objq3 = Clients.objects.raw('SELECT DISTINCT Id_Compra,MONTH(Fecha) as DateF FROM `HypermedialAPP_clients` WHERE Medio = "MercadoLibre"')
for fgh in objq3:
obj3qDate = fgh.DateF
for ghi in Clients.objects.raw('SELECT DISTINCT Id_Compra,COUNT(*)as MaxsML FROM `HypermedialAPP_clients` WHERE Medio = "MercadoLibre" and MONTH(Fecha) = %s GROUP BY Id_Compra', [fgh.DateF]):
obj_MLc = ghi.MaxsML
objq4 = Clients.objects.raw('SELECT DISTINCT Id_Compra,MONTH(Fecha) as DateF FROM `HypermedialAPP_clients` WHERE Medio = "MediosFisicos"')
for hij in objq4:
obj4qDate = hij.DateF
for ijk in Clients.objects.raw('SELECT DISTINCT Id_Compra,COUNT(*)as MaxsMP FROM `HypermedialAPP_clients` WHERE Medio = "MediosFisicos" and MONTH(Fecha) = %s GROUP BY Id_Compra', [hij.DateF]):
obj_MFc = ijk.MaxsMP
objq5 = Clients.objects.raw('SELECT DISTINCT Id_Compra,MONTH(Fecha) as DateF FROM `HypermedialAPP_clients` WHERE Medio = "WooCommerce"')
for jkl in objq5:
obj5qDate = jkl.DateF
for klm in Clients.objects.raw('SELECT DISTINCT Id_Compra,COUNT(*)as MaxsWC FROM `HypermedialAPP_clients` WHERE Medio = "WooCommerce" and MONTH(Fecha) = %s GROUP BY Id_Compra', [jkl.DateF]):
obj_WCc = klm.MaxsWC
obj = Clients.objects.all()
for abc in obj :
obj_Cliente = abc.Cliente
obj_Fecha = abc.Fecha
obj_Medio = abc.Medio
obj_ValorT = abc.ValorT
obj_months = Clients.objects.dates('Fecha', 'month')
obj2 = str(abc.Fecha)
obj3 = obj2[5:7]
if meses.has_key (obj3):
obj4 = meses[obj3]
abc.Fecha2=obj4
context = {
"obj" : obj,
"obj4" : obj4,
"obj_Cliente" : abc.Cliente,
"obj_Fecha" : abc.Fecha,
"obj_Medio" : abc.Medio,
"obj_ValorT" : abc.ValorT,
"objq1" : objq1,
"objq2" : objq2,
"objq3" : objq3,
"objq4" : objq4,
"objq5" : objq5,
"obj_FBc" : ced.MaxFB,
"obj_WPc" : dfg.MaxsWP,
"obj_MLc" : ghi.MaxsML,
"obj_MFc" : ijk.MaxsMP,
"obj_WCc" : klm.MaxsWC,
}
return render(request,"inicio.html",context)
The Output Shell is this
1
2
3
4
5
6
7
8
9
10
11
Internal Server Error: /inicio/
Traceback (most recent call last):
File "/home/miguelangelpc/HypermedialENV/local/lib/python2.7/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/miguelangelpc/HypermedialENV/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/miguelangelpc/HypermedialENV/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/miguelangelpc/HypermedialENV/HypermedialPRJ/HypermedialAPP/views.py", line 77, in inicio
"obj_MFc" : ijk.MaxsMP,
UnboundLocalError: local variable 'ijk' referenced before assignment
Can someone help me please
Valora esta pregunta
0