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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:06:57+00:00 2026-06-03T06:06:57+00:00

I am creating a little Django app with Users and I have created my

  • 0

I am creating a little Django app with Users and I have created my own UserProfile model.. But I have some issues with my urls(atleast I think). I think the regular expressions I have used are wrong. Check it out:

the error I get:

ValueError at /usr/tony/

invalid literal for int() with base 10: 'tony'

My url:

url(r'^usr/(?P<username>\w+)/$', 'photocomp.apps.users.views.Userprofile'),

My view:

from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.contrib import auth
from django.http import HttpResponseRedirect
from photocomp.apps.users.models import UserProfile

def Userprofile(request, username):
    rc = context_instance=RequestContext(request)
    u = UserProfile.objects.get(user=username)
    return render_to_response("users/UserProfile.html",{'user':u},rc)

here is my model:

from django.db import models
from django.contrib.auth.models import User

class UserProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    first_name = models.CharField(max_length="30", blank=True)
    last_name = models.CharField(max_length="30", blank=True)
    email = models.EmailField(blank=True)
    country = models.CharField(blank=True,max_length="30")
    date_of_birth = models.DateField(null=True)
    avatar = models.ImageField(null=True, upload_to="/avatar")
  • 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-03T06:06:58+00:00Added an answer on June 3, 2026 at 6:06 am
    u = UserProfile.objects.get(user__username=username)
    

    It looks like you are searching for the username attribute of user. Foreign keys are spanned in django by double underscores.

    https://docs.djangoproject.com/en/dev/topics/auth/

    https://docs.djangoproject.com/en/dev/topics/db/queries/

    Also .get() will throw a DoesNotExist exception it is advisable to wrap the query in try: except block so that it doesn’t 500 on the user.
    https://docs.djangoproject.com/en/1.2/ref/exceptions/#objectdoesnotexist-and-doesnotexist

    def Userprofile(request, username):
        rc = context_instance=RequestContext(request)
        try:
          u = UserProfile.objects.get(user__username=username)
        except UserProfile.DoesNotExist:
          # maybe render an error page?? or an error message at least to the user
          # that the account doesn't exist for that username?
        return render_to_response("users/UserProfile.html",{'user':u},rc)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a little calendar app in Django. I have two model classes; Calendar
I'm creating a little Silverlight LOB app. I created the app + web in
I'm creating my own little task system in Ruby on Rails, but I need
I'm considering creating a little chatbot that learns from users, similar to Clever-Bot (but
I'm creating a little photo sharing site for our home's intranet, and I have
I've been wondering how to do this for ages. I'm creating a little app,
I'm having little trouble creating a script working with URLs. I'm using urllib.urlopen() to
I'm creating a little paint app, and I want to give my painters the
I'm creating a little app that configures a connected device and then saves the
I am creating a little flash game for the facebook platform, but I am

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.