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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:25:08+00:00 2026-06-16T14:25:08+00:00

Model: class Car(models.Model): name = models.CharField(max_length=10, unique=True) def __unicode__(self): return self.name def get_absolute_url(self): return

  • 0

Model:

class Car(models.Model):
    name = models.CharField(max_length=10, unique=True)
    def __unicode__(self):
            return self.name
    def get_absolute_url(self):
        return reverse('cars.views.car', args=[str(self.id)])

View:

def car(request):
    all_cars = Car.objects.all().filter(active=1).values('id', 'name')
    return render(request, 'car.html', {'all_cars': all_cars})

URL mapping:

url(r'^car/$', 'cars.views.car'),

in car.html, I’m using:

<li><a href="{{ car.get_absolute_url }}">{{ car.name }}</a></li>

But it didn’t print /car/N/, only /car/. How to fix it? With this (<!-- BAD template code. Avoid! -->) it works, but dont works with get_absolute_url.

  • 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-16T14:25:09+00:00Added an answer on June 16, 2026 at 2:25 pm

    Your URL pattern doesn’t accept any argument, so django can’t generate an URL with the argument!

    url(r'^car/$', 'cars.views.car'), # Where would django add the parameter?!
    

    Should be:

    url(r'^car/(?P<car_id>\d+)/$', 'cars.views.car'),
    

    But then your car view wouldn’t work, because it looks like it gives a listing of cars.

    You probably want two URLS: one for a car listing, and one for a specific car. They’ll need to map to two different views:

    url(r'^car/$', 'cars.views.list_cars'), # List of all cars.
    url(r'^car/(?P<car_id>\d+)/$', 'cars.views.view_car'), # View a specific car, map get_aboluste_url to this view. 
    

    On a sidenote, you should look into generic views, they would make this entire process simpler.

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

Sidebar

Related Questions

My model: class Player(models.Model): player_name = models.CharField(max_length=50) player_email = models.CharField(max_length=50) def __unicode__(self): return self.player_name
models: class Detail(models.Model): def __unicode__(self): return self.title title = models.CharField(max_length=32) class Cars(models.Model): def __unicode__(self):
I have 2 models: class Producer(models.Model): def __unicode__(self): return self.name def get_absolute_url(self): return /prod/%i/
#model class Promotion(models.Model): name = models.CharField(max_length=200) start_date = models.DateTimeField() end_date = models.DateTimeField() #view def
in a django-tastypie app I have the following Django-models: class Car(models.Model): name=models.CharField('name',max_length=64) class CarTrack(models.Model):
This is the model: class Car(models.Model): user = models.ForeignKey(User, related_name='cars') name = models.CharField(max_length=64) Url
Let's supposed I created two models: class Car(models.Model): name = models.CharField(max_length=50) size = models.IntegerField()
Model: class Session(models.Model): tutor = models.ForeignKey(User) start_time = models.DateTimeField() end_time = models.DateTimeField() def __unicode__(self):
I have a following model: class Car(models.Model): make = models.CharField(max_length=40) mileage_limit = models.IntegerField() mileage
I have the following models: class Category(models.Model): name = models.CharField(max_length=200) slug = models.SlugField() parent

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.