1

I found the following very useful script while Googleing: https://github.com/shanealynn/python_batch_geocode/blob/master/python_batch_geocoding.py

This script is just what I need and it works flawlessly when I run it locally on my computer. I have a small Django site, where I would like to use this script (non commercially). I do not need a full code example (even though if someone has example code, just post it, I will get trough it) but rather the steps to take to make use of such a script. I googled a lot concerning this the last days and got a lot of different answers and differenct scenarios. Non of them really wholly apply to this scenario though:

  1. Upload CSV
  2. Run Script
  3. Create Link/Make Download possible of newly created CSV

Is anyone out there who might be able to help me out?

Thanks in advance and best regards

edit: Here are the steps and the code I got up until now:

I pretty much followed the following tutorial: https://docs.djangoproject.com/en/2.1/topics/http/file-uploads/

Here a my snippets:

forms.py

class UploadFileForm(forms.Form): title = forms.CharField(max_length=50) file = forms.FileField()

views.py

def geocode(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            handle_uploaded_file(request.FILES['file'])
            return HttpResponseRedirect('/success/url/')
    else:
        form = UploadFileForm()
    return render(request, '../templates/data/geocode/index.html', {'form': form})

urls.py

urlpatterns = [
...
path('geocode', views.geocode, name='geocode')]

The File Upload shows up and I am able to pick a file. This is the step where I do not know what to do though. Do I need to save it in my database or can I just load it into the script somehow?

2
  • 1
    Please provide your code and what you have done so far, we can help you improve your code towards the right solution. Commented Feb 12, 2019 at 14:03
  • edited my existing post with code snippets. Commented Feb 12, 2019 at 14:40

1 Answer 1

1

You can have your python script in your django project's directory and after the file is uploaded, execute the python script as described here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.