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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:51:13+00:00 2026-06-16T17:51:13+00:00

Till now i have been using userid’s (pk) as an argument in the profile

  • 0

Till now i have been using userid’s (pk) as an argument in the profile urls for my application. Recently i decided to use the username instead of the user id’s So i changed the following :

Urls.py

# This was what i was using previously
url(r'^profile/(?P<uid>\d+)/$', 'app.views.user_profile', name="profile"),

# Changed the above to this.
url(r'^profile/(?P<username>[-\w\d]+)/$', 'app.views.user_profile', name="profile"),

Views.py

# Previous view
@login_required
def user_profile(request, uid):

    user = get_object_or_404(models.User, pk=uid)
    profile = helpers.get_profile(user)
    render_to_response('profile.html', {'profile' : profile})


# Changed the above to
@login_required
def user_profile(request, username):

    user = get_object_or_404(models.User, username=username)
    profile = helpers.get_profile(user)
    render_to_response('profile.html', {'profile' : profile})

Until Now it’s all good. When i try to visit 127.0.0.1:8000/profile/some_username/ instead of the previous 127.0.0.1:8000/profile/some_number/ it works fine.

I have a toolbar in the profile.html, which contains links such as:

/profile/edit/
/profile/settings/

in the urls.py these urls map to very simple views. Such as the following.

@login_required
def profile_settings(request):
    """  
    This view helpers.renders the profile's settings panel
    """
    print 'hello'
    rec, can = helpers.get_user_or_noprofile(request.user)
    if not can is None:
        gform = forms.CandidateGeneralSettingsForm(instance=can)
        jsform = forms.CandidateJobSearchSettingsForm(instance=can)
        data = {'candidate' : can, 'gform' : gform, 'jsform' : jsform }
    else:
        form = forms.RecruiterSettingsForm(instance=rec)
        data = { 'recruiter' : rec, 'form' : form }
    return helpers.render(request, 'profile_settings.html', data)

The weird part is after i changed to use username in the profile url. As soon as i click on any of the links in the toolbar, i see the 404 : Error : No User matches the given query. page.

To debug i tried printing a few debug statements within these views and found out something more weird. Nothing gets printed even if i Comment the whole code inside the view and just write a print statement.

This makes me doubt that the problem might be with the login_required decorator. but if that’s the case howcome it is working while visitng 127.0.0.1:8000/profile/some_username/.

I really can’t think of anything that might be causing this. Any help will be greatly appreciated. Thanks.

PS: Also, JFYI, i am using a custom Email Authentication backend that lets user login through their email address instead of the username.

  • 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-16T17:51:14+00:00Added an answer on June 16, 2026 at 5:51 pm

    It doesn’t work because edit is not a valid username.

    This url /profile/edit/ matches ^profile/(?P<username>[-\w\d]+)/$, and username becomes edit.

    Since you don’t have a user called “edit”, this user = get_object_or_404(models.User, username=username) fails, and raises a 404.

    The same for /profile/settings/.

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

Sidebar

Related Questions

I have been using gcc, g++ for my C, C++ application development till now
I have been using jQuery 1.23 till now and nowadays most of the plugins
I have been using this code to parse xml till now. Its was working
Till now, I have been using Netbeans IDE for Java Applications. To distribute applications
I have been using Micah Carrick's PAYPAL IPN class till now for web_accept but
Till now, I have been using google charts and UIWebView to show graphs in
Till now I have been able to create an application where the Kinect sensor
I have been a C++ / Linux Developer till now and I am adept
I've been using RVM for quite some time now and have been very happy
My app runs on the google app engine Till now I have been downloading

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.