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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:16:29+00:00 2026-06-05T01:16:29+00:00

My views.py: @login_required def some_views(request): if request.method == ‘POST’: form = AddressCreateFrom(request.POST) if form.is_valid():

  • 0

My views.py:

 @login_required
 def some_views(request):
     if request.method == 'POST':
         form = AddressCreateFrom(request.POST)
         if form.is_valid():
             name = form.cleaned_data['Address']
             ip_value = form.cleaned_data['value']
             user_list = get_username(name)
             address_create = form.save()
             extra_context = {
                 'user_list': user_list
                 }
             return redirect_to(request, url=address_create.get_absolute_url())
     else:
         form = AddressCreateFrom()
     extra_context = {
         'form':AddressCreateFrom(initial={'user': request.user.pk})
         }
     return direct_to_template(request,'networks/user_form.html',extra_context)

In form.py:

 class AddressCreateFrom(forms.ModelForm):
     Address = forms.CharField(max_length=40)
     value = forms.CharField(max_length=40)
     class Meta:
         model = Network
         widgets = {
             'user': forms.HiddenInput()
           }

As you see that i am using Django model form with two extra Django form field i.e. Address and value in AddressCreateForm class. I need all of the field at the time of rendering the template.

Indeed some_views method are working fine but i also want render some extra data written in context_dictionary i.e. user_list to a requesting URL i.e. address_create.get_absolute_url().

If i am not wrong, if we are handling with the database we have to use redirect_to method. Is it possible to do that?

  • 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-05T01:16:30+00:00Added an answer on June 5, 2026 at 1:16 am

    A redirect will return a HTTP response with status code 301 or 302, and the location to redirect to:

    301 MOVED PERMANENTLY
    Location: http://www.example.com/new-url/
    

    There is no template rendered by the original view, so you can’t pass extra_context to it.

    The user’s browser will usually follow the redirect, and request the new URL.

    If you want to display information about a particular user in the next view, you have to do something like:

    1. design your URL pattern to include the user id, e.g. /users/200/,
    2. include it as a get parameter e.g. /users/?id=200, then fetch the user id from request.GET in the view.
    3. store the user_id in the session
    4. Before redirecting, create a message using the messages framework using the user data.

    Then in the view that you redirect to, you can fetch the user from the database, and add it to the template context.

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

Sidebar

Related Questions

I have used the inlineformset, the views method is as follows: @login_required def patron_edit_phone(request,
my app has a basic login function in views: def login_page(request): username = request.POST['username']
I'm using User authentication to all pages. Like this: @login_required(redirect_field_name='redirect_to') def memp(request): ... But
I'm using the standard authentication form. It's clean method looks like this : def
I'm working on some legacy Django code. I have two nearly-identical views: @login_required def
Is there any difference in using login_required decorator in urls.py and in views.py ?
I am attempting to invoke /save_calendar, mapped to pim_calendar.save_calendar(), which begins: @csrf_exempt @login_required def
I am doing registration in django using a form with overriding save method. I
Most of my views require login. Is there a way to specify that all
I'm using django.contrib.auth.views.login to log in users. When login is failed, the user and

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.