Expecting value: line 1 column 1 (char 0) Django form

I am getting error Expecting value: line 1 column 1 (char 0) when trying to add new company with Django form. I could not find duplicate questions on google so i want to ask for any help. My files are below

model.py

class Company(models.Model):
    
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=300, unique=True, blank=False, null=False)
    domains = ArrayField(models.CharField(max_length=100))
    licence_type = models.CharField(max_length=20, default='Demo')
    status = models.CharField(max_length=20, default='Passive')
    sector = models.CharField(max_length=100)
    security_score = models.IntegerField(default=0)
    licence_start_date = models.DateTimeField()
    licence_end_date = models.DateTimeField()
    insert_date = models.DateTimeField(default=timezone.now)

    def __str__(self):
        return self.name

forms.py

class AddCompanyForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(AddCompanyForm, self).__init__(*args, **kwargs)
        
    class Meta:
        model = Company
        exclude = ['security_score', 'insert_date', 'licence_start_date', 'licence_end_date']
        
    name = forms.CharField(
        required=True,
        widget=forms.TextInput(
            attrs={
                "class": "form-control",
                "id": "name",
                "placeholder": "Company Name"
            }
        ))

    sector = forms.CharField(
        required=False,
        widget=forms.TextInput(
            attrs={
                "class": "form-control",
                "id": "sector",
                "placeholder": "Company Sector"
            }
        ))

    domains = forms.CharField(
        required=True,
        widget=forms.Textarea(
            attrs={
                "class": "form-control",
                "id": "domains",
                "rows": "4",
                "placehoder":"Separate domains with comma (,)"
            }
        ))
    
    licence_date = forms.CharField(
        required=True,
        widget=forms.TextInput(
            attrs={
                "class": "form-control",
                "id": "licence_date",
            }
        ))
    licence_type = forms.ChoiceField(
        choices = [
            ('Demo', 'Demo'),
            ('Basic', 'Basic'),
            ('Pro', 'Pro'), 
            ('Enterprise', 'Enterprise')],
        required=True,
        widget=forms.Select(
            attrs={
                "class":"form-control select2",
                "id":"licence_type"
            }
        ))
    status = forms.ChoiceField(
        choices = [
            ('Passive', 'Passive'),
            ('Active', 'Active')],
        required=True,
        widget=forms.Select(
            attrs={
                "class":"form-control select2",
                "id":"status"
            }
        ))
    
    def clean_name(self):
        data = self.cleaned_data['name']
        if Company.objects.filter(name=data).count() > 0:
            raise forms.ValidationError("{} Company already exists".format(data))
        return data

views.py

When i change AddCompanyForm with AddUserForm error does not show anymore. So i think problem is my form class.

def add_company(request):
    form = AddCompanyForm(request.POST or None)
    if request.method == "POST":
        if form.is_valid():
            licence_datetime = request.POST.get('licence_datetime')
            split_licence_time = licence_datetime.split(' - ')
            start_time = split_licence_time[0].strip() #company licence start time
            end_time = split_licence_time[1].strip() #company licence end time
            start_time = datetime.strptime(start_time, '%m/%d/%Y')
            end_time = datetime.strptime(end_time, '%m/%d/%Y')
            form = AddCompanyForm(request.POST)
            company = form.save(commit=False)
            company.licence_start_date = start_time
            company.licence_end_date = end_time
            form.save()
            messages.add_message(request, messages.INFO, f'Company {name} added successfully')
            return http.HttpResponseRedirect(reverse('list_company'))
        else:
            print(form.errors)
    context = {
        "form":form,
        "segment":['company', 'admin_settings']
    }
    return render(request, 'account/company/add.html', context)

add.html

<form action="" method="post">
  {% csrf_token %}
  <div class="row">
    <div class="col-md-6">
      <div class="form-group">
        <label for="name">Company Name</label>
        {{ form.name }}
      </div>
    </div>
    <div class="col-md-6">
      <div class="form-group">
        <label for="companySector">Sector</label>
        {{ form.sector }}
      </div>
    </div>
  </div>
  <div class="form-group">
    <label for="domains">Domains</label>
    {{ form.domains }}
  </div>
  <div class="form-group">
    <label>Licence Start-End Datetime</label>
    <div class="input-group">
      <div class="input-group-prepend">
        <span class="input-group-text"><i class="far fa-clock"></i></span>
      </div>
      {{ form.licence_date }}
    </div>
  </div>
  <div class="row">
    <div class="col-md-6">
      <div class="form-group">
        <label>Licence Type</label>
        {{ form.licence_type }}
      </div>
    </div>
    <div class="col-md-6">
      <div class="form-group">
        <label>Status</label>
        {{ form.status }}
      </div>
    </div>
  </div>
  <div class="card-footer float-right">
    <button type="submit" class="btn btn-primary">Add Company</button>
  </div>
</form>
Environment:


Request Method: POST
Request URL: http://194.163.189.214/account/add/company

Django Version: 4.1
Python Version: 3.8.10
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'account',
 'dashboard',
 'phonenumber_field']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'login_required.middleware.LoginRequiredMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "/home/pdiscovery-bot/pdisenv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
  File "/home/pdiscovery-bot/pdisenv/lib/python3.8/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/pdiscovery-bot/threaddiscovery/account/views.py", line 116, in add_company
    if form.is_valid():
  File "/home/pdiscovery-bot/pdisenv/lib/python3.8/site-packages/django/forms/forms.py", line 205, in is_valid
    return self.is_bound and not self.errors
  File "/home/pdiscovery-bot/pdisenv/lib/python3.8/site-packages/django/forms/forms.py", line 200, in errors
    self.full_clean()
  File "/home/pdiscovery-bot/pdisenv/lib/python3.8/site-packages/django/forms/forms.py", line 439, in full_clean
    self._post_clean()
  File "/home/pdiscovery-bot/pdisenv/lib/python3.8/site-packages/django/forms/models.py", line 492, in _post_clean
    self.instance.full_clean(exclude=exclude, validate_unique=False)
  File "/home/pdiscovery-bot/pdisenv/lib/python3.8/site-packages/django/db/models/base.py", line 1464, in full_clean
    self.clean_fields(exclude=exclude)
  File "/home/pdiscovery-bot/pdisenv/lib/python3.8/site-packages/django/db/models/base.py", line 1516, in clean_fields
    setattr(self, f.attname, f.clean(raw_value, self))
  File "/home/pdiscovery-bot/pdisenv/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 754, in clean
    value = self.to_python(value)
  File "/home/pdiscovery-bot/pdisenv/lib/python3.8/site-packages/django/contrib/postgres/fields/array.py", line 126, in to_python
    vals = json.loads(value)
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None

Exception Type: JSONDecodeError at /account/add/company
Exception Value: Expecting value: line 1 column 1 (char 0)

Back to Top