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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:24:22+00:00 2026-05-15T17:24:22+00:00

I am working on integration of django application with facebook and i did almost

  • 0

I am working on integration of django application with facebook and i did almost but I want to give an facility to the user to select his/her username after he/she successfully logged in facebook on my django site here is the code :

form for usename :

class RegisterUsernameForm(forms.Form):

username = forms.RegexField(regex=r'^\w+$',
                            max_length=30,
                            widget=forms.TextInput(attrs=attrs_dict),
                            label=_(u'username'))

def clean_username(self):
    """
    Validate that the username is alphanumeric and is not already
    in use.

    """
    try:
        user = User.objects.get(username__iexact=self.cleaned_data['username'])
    except User.DoesNotExist:
        return self.cleaned_data['username']
    raise forms.ValidationError(_(u'This username is already taken. Please choose another.'))

made an template against it as well

here is the view which i used to use the from

def register_username(request, form_class=RegisterUsernameForm,
template_name=’registration/register_username_form.html’,
extra_context=None):

    if request.method == 'POST':
        form = form_class(data=request.POST, files=request.FILES)
        if form.is_valid():
            username = form['username'].data
            return HttpResponseRedirect(reverse('facebook_settings'))
    else:
        form = form_class()

    if extra_context is None:
            extra_context = {}
    context = RequestContext(request)
    for key, value in extra_context.items():
        context[key] = callable(value) and value() or value
    return render_to_response(template_name,
                          { 'form': form },
                          context_instance=context)

in which i am just getting the username from the from…

I have one fb_authenticate on my django application in which i am check whether user exist in my db or not if not then create new one at that point of time i need to redirect that form “username” which i have above mention . so user can select it and then will register him in dgango app

class FbBackend:

def fb_authenticate(self, request, facebook_id=None):
    if not facebook_id: return None
    try:
        profile = UserProfile.objects.get(facebook_id=facebook_id)

        #To Check whether the same user is loggin in to facebook if not then logout the perivous one and login new one.
        if request.user != profile.user :
           from django.contrib.auth import logout
           logout(request)
           request.user=profile.user

        UpdateFbUserDetails(request, profile.user, facebook_id)
        return profile.user
    except UserProfile.DoesNotExist:
        # No user. Create one.
        pass

    #Get user facebook account details like first name, last name and email address. 
    username = request.facebook.users.getInfo([request.facebook.uid], ['name'])[0]['name']
    firstname = request.facebook.users.getInfo([request.facebook.uid], ['first_name'])[0]['first_name']
    lastname = request.facebook.users.getInfo([request.facebook.uid], ['last_name'])[0]['last_name']
    emailaddress = request.facebook.users.getInfo([request.facebook.uid], ['email'])[0]['email']

    # Create the username for facebook logged in user 
    fbusername = (emailaddress.rsplit ('@')[0]).replace ('.','') + "_"+((emailaddress.rsplit ('@')[1])[0]).capitalize()


    try:
        user = User.objects.get(email=emailaddress)
        # This shouldn't really happen. Log an error.
        # logging.error('Strange: user %s already exists.' % username)
    except User.DoesNotExist:
        user = User.objects.create_user(fbusername,emailaddress,'xxxx')#('fb_%s' % facebook_id, '')
        user.first_name = firstname 
        user.last_name = lastname

    if not UpdateFbUserDetails(request, user, facebook_id):
        return None
    user.save()
    profile, created = UserProfile.objects.get_or_create(user=user)
    profile.facebook_id = facebook_id
    new_basics_info = UserBasicInfo()
    new_basics_info.full_name = username
    new_basics_info.save()
    profile.basics_info = new_basics_info
    new_personal_info = UserPersonalInfo()
    new_personal_info.save()
    profile.personal_info = new_personal_info
    profile.save()
    return user

Please help me how i can achieve it……

Thanks

Ansh J

  • 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-05-15T17:24:23+00:00Added an answer on May 15, 2026 at 5:24 pm

    I have solve it ….

    I just put all the saving code in view file after :

    if form.is_valid():
    and the when user is logged in I navigate him to that page and when he select join then will get registered in my django application .

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

Sidebar

Related Questions

I'm working with django and doing facebook integration for which is needed a test
My Paypal integration stopped working on 9/13/12 with my Java application. I did some
I am working on facebook integration in my application. Facebook returns users timezone in
I'm working on an integration with the Facebook Timeline and want to have a
I am working on a rails application. I have implemented facebook integration in my
I've try to implement integration tests for a working application (spring, hibernate, soap, cxf).
I'm currently working on what I would call integration tests. I want to verify
I am working on creating Integration test cases for my rest controller. I want
I am working on a integration test application, this is what I am doing
I have the following repository layout: master branch (production) integration working What I want

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.