django-formset Issue -  VM88:1 Uncaught (in promise) SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON VM89:1 Uncaught (in promise) SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON

I am facing the following issue while using django-formset

VM88:1 Uncaught (in promise) SyntaxError: Unexpected token ‘<’, "<!DOCTYPE "… is not valid JSON
VM89:1 Uncaught (in promise) SyntaxError: Unexpected token ‘<’, "<!DOCTYPE "… is not valid JSON

class OfficeDetailCreateView(AdminUserTypeAuthMixin,FileUploadMixin, FormViewMixin, LoginRequiredMixin, CreateView):
model = Officedet
template_name = ‘home/crud/crud_template.html’
form_class = OfficedetForm
success_url = reverse_lazy(‘office_list_view’) # or whatever makes sense
extra_context = {
‘pagetitle’:‘Office Creation’

class OfficedetForm(forms.ModelForm):

office_logo = fields.FileField(
    label="Office Logo",

office_gender_type = forms.ModelChoiceField(
        placeholder="Choose Gender",

office_mgnt_type = forms.ModelChoiceField(
        placeholder="Choose Management",

office_class_level = forms.ModelChoiceField(
        placeholder="Choose Class Level",

office_place = forms.ModelChoiceField(
        placeholder="Choose Place",

office_type = forms.ChoiceField(
    choices=[ ('SCHOOL','SCHOOL'),

default_renderer = FormRenderer(
        '*': 'mb-2 col-12', 
        "office_code": 'mb-2 col-2', 
        "office_name": 'mb-2 col-4',
        "office_mail": 'mb-2 col-3',
        "office_place": 'mb-2 col-3',
         '*': 'mb-2 col-12', 
        "office_gender_type": 'mb-2 col-3', 
        "office_mgnt_type": 'mb-2 col-3',
        "office_class_level": 'mb-2 col-3',
        "office_type": 'mb-2 col-3',

         '*': 'mb-2 col-12', 
        "office_tanno": 'mb-2 col-4', 
        "office_udisecode": 'mb-2 col-4', 
        "office_logo": 'mb-2 col-4', 

class Meta:
    model = Officedet
    fields = ["office_code",


{% extends “layouts/masterpage-formset.html” %}
{% block pagecontent %}
{% load render_form from formsetify %}

{% render_form form %}

Submit Reset Back to list
{% endblock pagecontent %}

Side note: When posting code here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted.

What do you mean by:

Those aren’t standard Python error messages.

Please provide additional details about exactly how and where you’re seeing these messages.

Also, what is this formsetify package? Your package or a generally-available third-party package? What is this render_form tag?

look like i have same problem when submitting my register form with ajax the form goes successfully but it doesn’t redirect to login page and no other feedback or error in UI webpage
" # error in displayed in my webpage console below "

`` (index):119 Error: SyntaxError: Unexpected token ‘<’, "

<!DOCTYPE "... is not valid JSON ```. here my my ajax form validation codes below ```

It looks like your AJAX might be expecting a JSON response instead of an HTML response. If that’s the case, then you need to either change your view to return JSON instead of HTML, or change your AJAX to expect an HTML response.

Also note that an AJAX response is not going to redirect your page. It’s up to you to know how to handle those issues within your JavaScript.

1 Like