44 views
Skip to first unread message

fahad rasool

unread,
Apr 27, 2020, 8:11:32 PM4/27/20
to django...@googlegroups.com
How to retrieve data from database and display on web page ,example i want to display the details of the user on  a web page which he has entered in a form which is stored in database.

_M_A_Y_A_N_K_

unread,
Apr 27, 2020, 10:44:53 PM4/27/20
to django...@googlegroups.com
You can create a function based view  or class based view (views.py) where you can have our own queryset to retrieve the data from database.
And pass the same into the html. 

Thanks & Regards,
---------------------
Mayank Tripathi
"Do what you can, with what you have, where you are -by Theodore Roosevelt"



On Mon, Apr 27, 2020 at 7:11 PM fahad rasool <rasoolf...@gmail.com> wrote:
How to retrieve data from database and display on web page ,example i want to display the details of the user on  a web page which he has entered in a form which is stored in database.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACqgSmA0Cjjx8S_SqeGF1wBDQggGAXszKdApOD45-1CPBPXG0g%40mail.gmail.com.

Chucky Mada Madamombe

unread,
Apr 27, 2020, 11:24:37 PM4/27/20
to django...@googlegroups.com
You can use generic class based views and an html template. 

Regards

Chuck G. Madamombe
NAM: +264 81 842 1284
RSA: +27 78 208 7034
Twitter: @chuckygari
Skype: chuckygari
Facebook: Chucky Mada Madamombe
LinkedIn: Chucknorris Garikayi Madamombe

On Tue, 28 Apr 2020, 02:11 fahad rasool <rasoolf...@gmail.com> wrote:
How to retrieve data from database and display on web page ,example i want to display the details of the user on  a web page which he has entered in a form which is stored in database.

--

ngal...@gmail.com

unread,
Apr 27, 2020, 11:28:57 PM4/27/20
to django...@googlegroups.com

Hello Fahad

If you didn’t extend user model your view.py it will be like

@login_required

def userdetails(request):

    user_details = User.objects.get(username=request.user)

    context {

        "user_details": user_details,

    }

    return render(request, 'accounts/profile.html', context)

 

Then on your app.urls

from .views import user_details

 

app_name = "your_app_name"

 

urlpatterns = [

     path('details/', user_details, name="profile")

]

 

 

On profile.html

{% block content %}

 

    <div class="container">

        <p>First Name: {{user_details.first_name}}</p>

        <p>Last Name: {{user_details.last_name}}</p>

        <p>Email:{{user_details.email}} </p>

        ...

    </div>

{% endblock content %}

--

Shreyas S K

unread,
Apr 28, 2020, 6:39:10 AM4/28/20
to Django users

Please refer the attached.
PYDataaccess.jpg

fahad rasool

unread,
May 3, 2020, 10:06:08 AM5/3/20
to django...@googlegroups.com

I am unable to redirect to my login page from signup page and nor i am able to store sign up form details in the database .please someone help its urgent..
IMG_20200503_192402.jpg

Amitesh Sahay

unread,
May 3, 2020, 10:14:18 AM5/3/20
to django...@googlegroups.com
it should be return redirect('login')

please check

On Sunday, 3 May, 2020, 07:34:11 pm IST, fahad rasool <rasoolf...@gmail.com> wrote:



I am unable to redirect to my login page from signup page and nor i am able to store sign up form details in the database .please someone help its urgent..

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

fahad rasool

unread,
May 3, 2020, 10:24:26 AM5/3/20
to django...@googlegroups.com
Than also it is not working

Amitesh Sahay

unread,
May 3, 2020, 10:57:58 AM5/3/20
to django...@googlegroups.com
please show your app's urls.py, as well the errors

Regards,
Amitesh


fahad rasool

unread,
May 3, 2020, 12:45:18 PM5/3/20
to django...@googlegroups.com
IMG_20200503_220739.jpg

Motaz Hejaze

unread,
May 3, 2020, 3:17:37 PM5/3/20
to Django users
first remove all whitespaces in urls.py 

' login' should be 'login'

and then rename your login view to something else , maybe custom_login , or put your app urls before admin panel urls 

fahad rasool

unread,
May 4, 2020, 2:53:54 PM5/4/20
to django...@googlegroups.com
In my django project ,when a user sign up, a form is redirected to fill user information,further iam displaying this info on other page ,but whats happening is when i am dislaying the information of the current user who had logged in ,information of all users is displayed who had been signed up earlier.

Ernest Thuku

unread,
May 4, 2020, 3:20:07 PM5/4/20
to Django users
It means you have put remember password on in your browser settings..so the information that you have registered in a form from a user will be displayed.

On Mon, May 4, 2020, 21:53 fahad rasool <rasoolf...@gmail.com> wrote:
In my django project ,when a user sign up, a form is redirected to fill user information,further iam displaying this info on other page ,but whats happening is when i am dislaying the information of the current user who had logged in ,information of all users is displayed who had been signed up earlier.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

fahad rasool

unread,
May 4, 2020, 3:21:24 PM5/4/20
to django...@googlegroups.com

fahad rasool

unread,
May 4, 2020, 3:35:37 PM5/4/20
to django...@googlegroups.com
No man than also it shows same behaviour

Adedotun Richard

unread,
May 4, 2020, 4:00:44 PM5/4/20
to django...@googlegroups.com
Can you show your views.py let me check where you get it wrong?

You might be calling a wrong function to handle the output

On Mon, May 4, 2020, 7:53 PM fahad rasool <rasoolf...@gmail.com> wrote:
In my django project ,when a user sign up, a form is redirected to fill user information,further iam displaying this info on other page ,but whats happening is when i am dislaying the information of the current user who had logged in ,information of all users is displayed who had been signed up earlier.

--

Adedotun Richard

unread,
May 4, 2020, 4:09:08 PM5/4/20
to django...@googlegroups.com
For the form not saving can you show the error message received? Hope you did not forget to put csrf_token  above ur form in the template?

And your views.py for the register should be in quote
return redirect ('login')



On Sun, May 3, 2020, 3:04 PM fahad rasool <rasoolf...@gmail.com> wrote:

I am unable to redirect to my login page from signup page and nor i am able to store sign up form details in the database .please someone help its urgent..

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Famzaa

unread,
May 4, 2020, 5:33:08 PM5/4/20
to django...@googlegroups.com
please show mw your views.py


fahad rasool

unread,
May 4, 2020, 5:38:07 PM5/4/20
to django...@googlegroups.com
IMG_20200505_025129.jpg

fahad rasool

unread,
May 4, 2020, 8:40:01 PM5/4/20
to django...@googlegroups.com
I am working on project which is a diet planner,for that a user have to signup ,fill a form and them meal plan is generated,in that i have made two groups one for admin and other for customer,now i am unable to retroeve data of the customer who is logged in.

Motaz Hejaze

unread,
May 4, 2020, 9:25:44 PM5/4/20
to Django users
What do you need exactly ?? What is the error ?? Do you want to check for user type in templates or views ??? If this is your question ..


1 - use a custom user model 
2 - put user types dictionary in custom user model
3 - in your templates and views check the current user type by using request.user.type


On Tue, 5 May 2020, 2:39 am fahad rasool, <rasoolf...@gmail.com> wrote:
I am working on project which is a diet planner,for that a user have to signup ,fill a form and them meal plan is generated,in that i have made two groups one for admin and other for customer,now i am unable to retroeve data of the customer who is logged in.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Adedotun Richard

unread,
May 5, 2020, 12:14:18 AM5/5/20
to django...@googlegroups.com
Can you see that the Customer is not define that was the reason why it was underlined. Try and import your app model to your view.py:

from .models import *



Kasper Laudrup

unread,
May 5, 2020, 5:31:44 AM5/5/20
to django...@googlegroups.com
Hi Adedotun,

On 05/05/2020 06.12, Adedotun Richard wrote:
> Can you see that the Customer is not define that was the reason why it
> was underlined. Try and import your app model to your view.py:
>
> from .models import *
>

Please don't suggest doing wildcard imports. It is highly discouraged
for good reasons:

https://www.python.org/dev/peps/pep-0008/#id23

In this case it should hopefully be fine to simply do:

from .models import Customer

Avoiding wildcard imports will also make it possible for the linter to
underline missing names in the future.

Kind regards,

Kasper Laudrup

fahad rasool

unread,
May 5, 2020, 3:40:45 PM5/5/20
to django...@googlegroups.com
Can someone tell that how to perform an operation ,for example we retreive two numbers from database and want to add them and display on template in django

fahad rasool

unread,
May 6, 2020, 4:42:28 AM5/6/20
to django...@googlegroups.com
I want to ask that i am working on django platform on a project ,which is basically an system that generates a diet plan for user..

The flow is that a user has to register and sign up after registration, a form (userinfo form )is to be filled by user,on basis of which diet plan is generated.

Now my question is when the same user login second time ,i did not want userinfo form to be displayed again and and again,r ather i want user to redirect to userprofile page..

Please help i have stuck here for about 3 days..

Ilda Pedro

unread,
May 6, 2020, 6:09:56 AM5/6/20
to django...@googlegroups.com
hello fahad rasool.

just try this.
from django.shortcuts import redirect

return redirect('userprofile)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Adedotun Richard

unread,
May 6, 2020, 7:28:14 AM5/6/20
to django...@googlegroups.com
Can i see your views.py.
you can create a decorator.py that will help you handle that

something like: you create a decorator.py file
then do the following:
from django.http import HttpResponse
from django.shortcuts import redirect

def unauthenticated_user(view_func):
    def wrapper_func(request, *args, **kwargs):
        if request.user.is_authenticated:
            return redirect('home') #this can be whatever name you call your homepage or the page you want to redirect to
        else:
            return view_func(request, *args, **kwargs)

    return wrapper_func


then you go to your views and import the decorator.py

from django.contrib.auth import authenticate,
from django.shortcuts import render, redirect
from .decorators import unauthenticated_user,

then at the beginning of your userinfo view function you do this:

def userinfo(request):
    if request.user.is_authenticated:
        return redirect('home')

    else:
#then you recall the function that call the inserinfo form.

I hope this will be able to help you resolve the issue.

Kind regards.

Adedotun Richard



On Wed, May 6, 2020 at 9:41 AM fahad rasool <rasoolf...@gmail.com> wrote:
--

Nomeh Uchenna Gabriel

unread,
May 6, 2020, 2:28:40 PM5/6/20
to django...@googlegroups.com
That's quite easy - 
___________
models.py:
    class num(models.Model):
        item = models.BigIntegerField(...) 
___________
views.py:
    from . import models
    def funct(request):
        mdl = models.num.objects.get(id__exact=1)
        mdl2 = models.num.objects.get(id__exact=1)
        
        adds = int(mdl.item) + int(mdl2.item)
        dict = {"adds_temp" : adds}
        return render(request, "home.html", context=dict)

___________
templates/home.html

<pre>
  Addition: {{adds_temp}} 
</pre>



On Tuesday, May 5, 2020, fahad rasool <rasoolf...@gmail.com> wrote:
Can someone tell that how to perform an operation ,for example we retreive two numbers from database and want to add them and display on template in django

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACqgSmCzazz4W5AuwKOzgvyjSDAMbXwgD-B%3DkM%2BtG3T0t2Mb%3DQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages