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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:57:40+00:00 2026-05-19T21:57:40+00:00

I would like keep reusing some functions I’ve created on many of my django

  • 0

I would like keep reusing some functions I’ve created on many of my django views so I don’t have to write them over and over on every view.

So I created a folder with a __init__.py in it. In the same folder I also created a myfunctions.py file where I placed my functions I would like to reuse on my django views.

Here is just a very simple test function I put in myfunctions.py to see if if I can reuse the function and especially the variable from that function in my views:

def test_function():
    test_variable = 1

I would like to just call the test_function() on a view and to deliver the test_variable value (of 1 in this case) on a template I created. The template for theat view has already a tag {{ test_valiable }}.

My problem is that when I call the test_function() on my view I don’t see the test_variable value passed to the {{ test_valiable }} tag in the template associated with my view.

The way I called the function in my view is:

test_function()

What am I not doing right?

  • 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-19T21:57:41+00:00Added an answer on May 19, 2026 at 9:57 pm

    test_variable is a local variable so you cant see it after function finished.
    You should rewrite your function to this:

    def test_function():
        test_variable = 1
        return test_variable
    

    And use it in a views.py

    def View(request):
       result = test_function()
       return render_to_response('template', {'test_valiable' : result })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JSF app and would like to keep some state on
I have some database functions and would like to make those database functions accessible
I have various models of which I would like to keep track and collect
We have #1 and #2 spots we would like to keep, but because of
I have an sqlite database, and I would like to keep it read-only without
I would like to keep options in a Config class, so I don't need
I would like to use some different CSS for ie8 but keep just the
I have an auth module, and would like to keep a Login form in
I would like to keep the overhead at a minimum. Right now I have:
I currently have a controller were I would like to keep track of logging

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.