my django code shows me this error unindent does not match any outer indentation, read that it's about tabs and spaces, but nothing works for me. I will appreciate if someone take a look into my code.
views.py
from django.shortcuts import render, redirect
from django.http import HttpResponse
# Create your views here.
from .models import *
from .forms import OrderForm
from .filters import OrderFilter
def home(request):
orders = Order.objects.all()
customers = Customer.objects.all()
total_customers = customers.count()
total_orders = orders.count()
delivered = orders.filter(status='Delivered').count()
pending = orders.filter(status='Pending').count()
context = {'orders':orders, 'customers':customers,
'total_orders':total_orders,'delivered':delivered,
'pending':pending }
return render(request, 'accounts/dashboard.html', context)
def products(request):
products = Product.objects.all()
return render(request, 'accounts/products.html', {'products':products})
def customer(request, pk_test):
customer = Customer.objects.get(id=pk_test)
orders = customer.order_set.all()
order_count = orders.count()
**myFilter = OrderFilter()**
context = {'customer':customer, 'orders':orders, 'order_count':order_count, 'myFilter': myFilter}
return render(request, 'accounts/customer.html',context)
def createOrder(request, pk):
customer = Customer.objects.get(id=pk)
form = OrderForm(initial={'customer': customer})
if request.method == 'POST':
#print('Printing POST:', request.POST)
form = OrderForm(request.POST) #sending data into the form
if form.is_valid():
form.save()
return redirect('/')
context = {'form': form}
return render(request, 'accounts/order_form.html', context)
def updateOrder(request, pk):
#prefill forms after click update
order = Order.objects.get(id=pk)
form = OrderForm(instance=order)
#save the changes
if request.method == 'POST':
form = OrderForm(request.POST, instance=order) #sending data into the form
if form.is_valid():
form.save()
return redirect('/')
context = {'form': form}
return render(request, 'accounts/order_form.html', context)
def deleteOrder(request, pk):
order = Order.objects.get(id=pk)
if request.method == 'POST':
order.delete()
return redirect('/')
context = {'item': order}
return render(request, 'accounts/delete.html', context)
The error it shown is on the 37 line I will make it bold. Thank you for your time devs.
Edit: tried to make it bold while it's in code mode but it shows it in **. The line is myFilter = OrderFilter() in customer function, where the error is shown.
Tried python -m tabnanny views.py
and it shows exactly the error message 'views.py': Indentation Error: unindent does not match any outer indentation level (, line 37)
I just fix it on VScode to convert tabs into spaces press F1, then Convert Indentation to Spaces