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

  • Home
  • SEARCH
  • 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 4052424
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:19:05+00:00 2026-05-20T14:19:05+00:00

I am new to Django I have a MySQL database – which I want

  • 0

I am new to Django
I have a MySQL database – which I want to update using a csv file. I intend to use the LOAD DATA command of MySQL
How do I go about it? – or is there a better way ?

How should I create the upload form?

  • 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-20T14:19:05+00:00Added an answer on May 20, 2026 at 2:19 pm

    You can use the csv module in Python to read the file and loop over the rows:

    import csv
    
    csv_file = open('path/to/file', 'rb')
    reader = csv.reader(csv_file)
    
    for column1, column2, column3 in reader:
        #do something with the data here
    

    Hope that helps!

    This section is a followup showing a sample view:

    #NOT TESTED
    import csv
    
    from django.shortcuts import render_to_response
    
    form my_app.forms import MyForm
    from my_app.models import MyModel
    
    def my_view(request):
        if request.method == 'GET':
            form = MyForm()
        else:
            form = MyForm(request.FILES, request.POST)
            if form.is_valid():
                the_file = form.cleaned_data.get('the_file_field', None)
                if the_file:
                    reader = csv.reader(the_file)
                    for column1, column2, column3 in reader:
                        my_model = MyModel.objects.create(column1=column1, \
                        column2=column2, column3=column3)
        return render_to_response('my_template.html', {'form' : form})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing PostgreSQL database that I'm using for a new Django site.
I'm new to Django and have only been using sqlite3 as a database engine
I'm fairly new to Django and have a basic question: I want to use
I'm rather new to Django and I'm using Django 1.0. I have this: forms.py:
I'm new to django. I have 2 simple objects, lets call them - File
I use the django admin for updating various data on the MySQL database. I
Everybody have to change the settings.py file every time you start a new django
I am evaluating using CouchDB in my new Django-project. Is there a good database
We're about to deploy a new Django website, and we want to use Google
I am rather new to django templates and have an impression that I have

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.