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 8105879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:17:02+00:00 2026-06-06T00:17:02+00:00

In my django app,I need to create a mapping between a username and a

  • 0

In my django app,I need to create a mapping between a username and a filename.When a user selects a particular file ,the program would associate a mapping between that username and the filename.

To use a python dictionary,I tried as follows:

views.py
----------

uname_file_map ={}

def user_select_file(request):
    filename = get_filename_from_request()
    username = request.user.username
    uname_file_map[username] = filename
    ....

def do_some_file_ops(request):
   username = request.user.username
   process_file_contents(uname_file_map.get(username))
   ...

It works without any problem when I use two browsers(chrome and firefox) , login as two different users and select two different files. What I am wondering is,will this break if many users login at the same time and select different files,since the same dictionary instance is used by all.

Is using two database tables User with a filename_id field and Filename a better solution? Or is the dictionary sufficient?

  • 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-06-06T00:17:04+00:00Added an answer on June 6, 2026 at 12:17 am

    Why don’t you use a model to achieve what you are looking for ?

    class FileMapping(models.Model):
        user = models.ForeignKey(User)
        file_name = models.CharField(_('filename'))
    
    
    def user_select_file(request):
        filename = get_filename_from_request()
        fm = FileMapping(user=request.user, file_name=filename)
        ....
    
    def do_some_file_ops(request):
       fm = FileMapping.objects.filter(user=request.user)
       process_file_contents(fm)
    

    I think it is more “django friendly” than using a pure python solution that would need to be checked for several security issues such as concurrence as you mention.

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

Sidebar

Related Questions

In a django app, I need to create twitter user profile urls with following
I want to create a very simple python web app. I don't need Django
I have a place in my Django app where I need to construct a
I need to develop an app that runs side by side with a django-app.
I have a Django app that use a django-tagging. I need to port this
Somebody know how use OpenX (php app) with Django? I need to use OpenX
I'm using django for a website app, mostly. I need to write a canvas
I need to create a Python REST/JSON web service for an iOS app to
I want to create a django app that can upload and display images. However
In the app we're developing using Django, in some cases we need to automatically

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.