0xE111 / django-mptt-urls

Creating hierarchical URLs in Django associated with django-MPTT models
MIT License
36 stars 5 forks source link

how can i access the urls as links? #7

Closed asing177 closed 8 years ago

asing177 commented 8 years ago

how can i access the urls as links?

http://best-photographer.com/gallery/weddings/Dexter-and-Rita/ http://best-photographer.com/gallery/my-pets/dogs/husky/

0xE111 commented 8 years ago

Move your cursor over the link and press left mouse button

asing177 commented 8 years ago

these are static...cant they be made dynamic...like url 'categories'

0xE111 commented 8 years ago

@adityasingh177 I absolutely totally don't understand what you're saying. If you want to get dynamic urls for any category instance, use instance.get_absolute_url()

asing177 commented 8 years ago

it doesnt work when i am calling the instance.get_absolute_url() from another page that is outside the mptt tree...

0xE111 commented 8 years ago

You should provide code example.

asing177 commented 8 years ago

Another.html

Categories :- weddings > Dexter and Rita My Pets > Dogs > Husky

'''

'''

i am a beginner. How can i give Links in "a hrefs " here....thanks in advance...

0xE111 commented 8 years ago

From your views.py pass desired instances to your template, like this:

def another_page(request):
    return render(
        request,
        'another.html',
        {'categories': Category.objects.all()}
    )

Then in another.html:

{% for category in categories %}
    {{ category.get_absolute_url }}
{% endfor %}

Note that in your models.py file you need to set up def get_absolute_url() for your Category model, as described here https://github.com/c0ntribut0r/django-mptt-urls in section get_absolute_url().