0

Say, I've got 2 views in views.py: Fetching_information_view and Processing_view.

In Fetching_information_view I am fetching information which I am displaying to the user in the tabular format on the "home.html" page. That's all okay.

Now, I get a CSV URL for each row as well. I don't want that when the user clicks on the CSV URL it should open the CSV; instead, when the user clicks on it then it should go to the Processing_view and it should be served on a different HTML page, say "process.html".

CSV URL:

/some_bucket/some_csv_file.csv?AWSAccessKeyId=some_id&Expires=1234&Signature=some_signature

Desired URL:

http://example.com/process.html?file=some_bucket/some_csv_file.csv?AWSAccessKeyId=some_id&Expires=1234&Signature=some_signature

Now, how can I call Processing_view from the Fetching_information_view view and send the file information? It should process in the backend and display results on process.html.

This is the table I am showing on the homepage:

enter image description here

I've wrote sample code for views.py which I'm using:

def process_data(request):
    # what should come here?
    # Display in process.html


def home(request):
    some_data = SomeTable.objects.filter(user = request.user)
    args = {"some_data": some_data}
    # display as table on home.html, including URLs it is carrying
    return render(request, "home.html", args)
2
  • Assuming you have a urlpattern process_view for your process_data view, in your template "home.html" you can just put href="{% url 'process_view' %}?id={{id}}" to append the id of the object to your request.GET. In the process view you fetch the model with that id and the associated CSV url and file parameters. Commented Oct 12, 2018 at 20:18
  • Thanks a lot, it works. Please write it as an answer, I will accept and upvote it. Commented Oct 14, 2018 at 0:09

1 Answer 1

2

If you don't want to expose the URL of your CSV files, then don't add it (and also don't expose the URL parameters) to the context of your home view and template.

So assuming you've created a urlpattern named process_view for your process_data view, in your home.html template you can just use href="{{% url 'process_view' %}?id={{ id }}" to append the id of the object to your request's URL parameters.

Then in the process_data view, you can get this id by id = request.GET.get('id'), fetch the model with this id and reconstruct the CSV url and file parameters.

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.