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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:28:40+00:00 2026-06-08T11:28:40+00:00

I have a same template that is used for different urls (in this case:

  • 0

I have a same template that is used for different urls (in this case: /create/ and /edit/[PK of an item] , named “create” and “edit” in the url.py).

I would like to show different things in my template depending if I’m on /edit/ or /create/.

How can I check this ?
{% if '/create' in request.path %} works, but I’d like to use a url tag (or equivalent, to not have it “hard coded”).
What I would like to do looks like (in pseudo code – this doesn’t work) {% if request.path in url create %} XXX {% endif %}.

Should I make all the necessary tests in the views.py, send a variable about it in the context, test on this variable in the template? In my case it seems a bit heavy for a simple url test …

  • 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-08T11:28:41+00:00Added an answer on June 8, 2026 at 11:28 am

    I’d say go for making two views if it’s a significant difference (different form, etc.) – eliminates url logic in templates entirely, and no real ‘test’ needed either – don’t have to check request.path/pass url/etc.

    urls

    urlpatterns = patterns('',
        (r'^create/$', create),
        (r'^edit$', edit),
    )
    

    views

    def create(request):
        text = "Create something"
        return render_to_response('same-template.html', {'text': text}, context_instance=RequestContext(request)
    
    def edit(request):
        text = "Edit something"
        return render_to_response('same-template.html', {'text': text}, context_instance=RequestContext(request)
    

    template

    {% text %}
    

    Can also pass multiple changes easily with a list this way too:

    views

    def create(request):
        data = []
        data['text'] = "Create something"
        data['form'] = CreateForm()
        return render_to_response('same-template.html', {'data': data}, context_instance=RequestContext(request)
    
    def edit(request):
        data = []
        data['text'] = "Edit something"
        data['form'] = EditForm()
        return render_to_response('same-template.html', {'data': data}, context_instance=RequestContext(request)
    

    template

    {% data.text %}
    {% data.form %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple HTML template that's used multiple times across the document. It's
I currently have a couple different user controls that provide the same functionality: three
Is it possible to have same table name on different schema with different data
Html text box should have same font size for both upper and lower case
Is it possible to have same hashcode for different strings using java's hashcode function?or
I have the same problem that is listed in the following thread. WSDL first
I would like to create a custom WPF control that inherits from comboBox. So
I have a class that uses an add-on template to add additional functionality as
I would like to know if there's any templating engine that is used for
I am increasingly annoyed by the unnecessarily verbose template that is used when I

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.