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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:46:28+00:00 2026-06-04T07:46:28+00:00

I have this code: class StoryViewClass(ListView): … some listview methods here for one set

  • 0

I have this code:

class StoryViewClass(ListView):

... some listview methods here for one set of urls

def saveStory(self,request,context_object_name,
              template_name,
              success_template):
    if request.method == "POST":
        form = StoryForm(request.POST)
        form.user = request.user.id
        if form.is_valid():
            form.save()
            if (success_template):
                return render_to_response(success_template)
            else:
                return render_to_response('accounts/addStorySuccess.html')
    else:
        form = StoryForm()
    if (context_object_name):
        contextName = context_object_name
    else:
        contextName = 'form'
    if (template_name):
        return render_to_response(template_name,{contextName:form})
    else :
        return render_to_response('accounts/addStory.html',{contextName:form})

(which is itself klunky, more on that later)

how do i call this from my url?

I am currently trying this:

url(r'^addStory/$',
    StoryShowView.saveStory(
        context_object_name='form',
        template_name='accounts/addStory.html',
        success_template='accounts/addStorySuccess.html'
    )
),

but django complains that

unbound method saveStory() must be called with StoryShowView instance as first argument (got nothing instead)

Request Method:     POST

What i am asking:

  1. how do i call this method (as a method of a class) from the urls.py?
  2. is there a simpler way to make the method “dynamic” or what have you – i mean, so i do not need to have all those ugly “if” blocks there to check what has been set and default if necessary?
  • 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-04T07:46:29+00:00Added an answer on June 4, 2026 at 7:46 am

    That’s not how you use Django’s class-based views. These must be referred to from urls.py via the as_view() method. They’re not meant to have more than one view-rendering method per class – if you need that, it’s best to put common code in a base class and subclass it. But in your case, you probably just want to use the existing methods more – for example, to work out which template to render, you should override get_template_names().

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

Sidebar

Related Questions

I have this code: class DocumentIdentifier attr_reader :folder, :name def initialize( folder, name )
So I have this code: class Door # ... def info attr = return
Let's say I have this code: class class1(object): def __init__(self): #don't worry about this
Suppose I have this code: class Example(object): def the_example(self): itsProblem = "problem" theExample =
Hello i have this code class Test(object): def start_conn(self): pass def __init__(self): self.conn =
Scenario: I have this code: class MyActor extends Actor { def act() { react
I'm a beginner in Android. Here I have this code: public class GPS extends
I have this code: class API(object): def __init__(self): self.baseuri = http://api.xxx.xxx self.cj = cookielib.CookieJar()
So for example I have this code: class Object{ public $tedi; public $bear; ...some
Suppose I have this code: class Num: def __init__(self,num): self.n = num def getn(self):

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.