How to modify the default get_absolute_url value of Django Auth. User

Source: Internet
Author: User

# Django # the user's URLs setting problem occurs after you use USERPROFILE, the get_absolute_url of user model is/users/<username>/by default in Django's auth app. If you have extended and implemented a USERPROFILE, you may need to use USERPROFILE. to use get_absolute_url, You need to redefine Auth. the user's absolute URL.

The get_absolute_url of user in auth. models is defined as follows:

    def get_absolute_url(self):        return "/users/%s/" % urllib.quote(smart_str(self.username))

Here it is fixed, but Django still gives a method to modify it.

The method is: Add a setting in settings. py: absolute_url_overrides

ABSOLUTE_URL_OVERRIDES = {    'blogs.weblog': lambda o: "/blogs/%s/" % o.slug,    'news.story': lambda o: "/stories/%s/%s/" % (o.pub_year, o.slug),}

Therefore, for Auth. User, modify the parameters as follows:

Absolute_url_overrides = {'auth. user': Lambda U: "/member/profile/% S/" % u. username, # other settings}

Official documents: https://docs.djangoproject.com/en/1.1/ref/settings/#absolute-url-overrides

Https://code.djangoproject.com/wiki/ReplacingGetAbsoluteUrl

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.