Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6745093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:09:46+00:00 2026-05-26T12:09:46+00:00

I am trying to build a import form for a CSV file into the

  • 0

I am trying to build a import form for a CSV file into the admin interface for a given model. the view can be reached from the change_list of the model, but it throws a template syntax error.

What am I doing wrong? Do I have to create my own template or can I re-use the existing admin/change_form.html somehow and I just don’t get it?

Traceback

Line 60 is highlighted.

Template error:
In template site-packages\django\contrib\admin\templates\admin\change_form.html,
    error at line 60
Caught KeyError while rendering: 'opts'
50 : {% endfor %}
51 : 
52 : {% block after_field_sets %}{% endblock %}
53 : 
54 : {% for inline_admin_formset in inline_admin_formsets %}
55 :     {% include inline_admin_formset.opts.template %}
56 : {% endfor %}
57 : 
58 : {% block after_related_objects %}{% endblock %}
59 : 
60 :  {% submit_row %}
61 : 
62 : {% if adminform and add %}
63 :    <script type="text/javascript">document.getElementById("{{ adminform.first_field.id_for_label }}").focus();</script>
64 : {% endif %}
65 : 
66 : {# JavaScript for prepopulated fields #}
67 : {% prepopulated_fields_js %}
68 : 
69 : </div>
70 : </form></div>

views.py

def import_tags(request):
    if request.method == "POST":
        form = RfidImport(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            success = True
            context = {"form": form, "success": success}
            return HttpResponseRedirect("../")
    else:
        form = RfidImport()
        context = {"form": form}
        return render_to_response("admin/change_form.html", context,
            RequestContext(request))

forms.py

class RfidImport(forms.ModelForm):
    file_to_import = forms.FileField()

    class Meta:
        model = RfidTag
        fields = ("file_to_import", )

    def save(self, commit=False, *args, **kwargs):
        form_input = RfidImport()
        file_csv = self.cleaned_data['file_to_import']
        csv.register_dialect('excel-new', delimiter=';', quoting=csv.QUOTE_NONE)
        records = csv.reader(file_csv, dialect='excel-new')
        for line in records:
            self.system = line[0]
            self.tagId = line[1]
            self.serial = line[2]
        form_input.save()
    datafile.close()

admin.py

class RfidTagAdmin(admin.ModelAdmin):
    list_display = ('tagId','serial', 'system', 'user')

    def get_urls(self):
        urls = super(RfidTagAdmin, self).get_urls()
        my_urls = patterns('',
            (r'^import/$', self.admin_site.admin_view(import_tags))
        )
        return my_urls + urls

    pass

admin.site.register(RfidTag, RfidTagAdmin)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:09:47+00:00Added an answer on May 26, 2026 at 12:09 pm

    You definitely need to use your own template, or modify the change form but also modify the change view. For example, it should be trivial to add this import into the change form itself.

    Django’s admin uses a lot of magical things for its admin, and those templates have many tags that are specific to the objects passed in via its change/changelist views.

    Extend admin/base_site.html instead and you’re good to go.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying build a method which returns the shortest path from one node to
Using PyClips, I'm trying to build rules in Clips that dynamically retrieve data from
So I'm trying to build a tabs view for an Android app, and for
I'm trying to build hello world on Objective-C on Linux (Ubuntu). main.c #import <Foundation/Foundation.h>
I'm trying to build a web app that grabs fantasy sports info from Yahoo's
I'm trying to build python 2.5.2 on Solaris 8 using gcc 3.4.2. I can't
I am trying to import a tab delimited file after upload. The meat of
I am trying to build a calendar view using django and trying to avoid
hey I'm trying to build this simple debugger class so i can see flash
I am trying to build the OpenGL SO lib from android sources (libGLESv2.so) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.