django-views Questions

17

Solved

I'm getting a ValueError when running python manage.py test. My project is named fellow_go, and I'm currently working on an App called pickup. Please note that this error is added in a relatively ...
Unprintable asked 24/5, 2017 at 14:1

1

Currently I have a project using django and rest_framework to get some basic APIs on the run. The problem is, when i make a view using the generic lib on rest_framework and DjangoModelPermissions, ...

4

Solved

I am new to Django Rest Framework. Using serializer and views a simple CRUD is easy. When the logics increase, it is quite confusing where to write logics in serializer or views. Some developers do...

1

I have category and subcategory store in my database, and subcategory is related to category, I have multiple pages on my website, but I am able to display category in the menu on some pages, but I...

5

I have a url mapping that looks like this: url(r'^(?P<lang>[a-z][a-z])/$', MyTemplateView.as_view()), There are only a few values that I accept for the lang capture group, that is: (1) ro ...
Herron asked 25/10, 2011 at 4:36

3

Solved

I am using distinct to get the distinct latest values but it is giving me an error: DISTINCT ON fields is not supported by this database backend views.py class ReportView(LoginRequiredMixin, ...

1

I have the same code block in four of my functions. Is there a way that can avoid repeating the same code block? Here is the same code block: def function_name(): # ...some code... hot_news_48h =...
Groschen asked 17/8, 2018 at 22:55

3

How do I add extra context to all admin webpages? I use default Django Admin for my admin part of a site. Here is an url entry for admin: urlpatterns = [ url(r'^admin/', admin.site.urls), ] A...
Echinate asked 13/9, 2016 at 18:8

16

In my view function, I'd like to return a json object (data1) and some text/html (form). Is this possible? MY code @api_view(['POST']) @permission_classes((AllowAny,)) def create_user(request): if...
Hepzi asked 14/7, 2016 at 6:21

4

Solved

When I want to select objects with a get() function like personalProfile = World.objects.get(ID=personID) If get function doesn't return find a value, a "matching query does not exist." error oc...
Arianism asked 14/10, 2015 at 7:44

5

Solved

In django framework,When there are changes in urls.py or model.py or views.py .We would restart httpd. But as the documentation says we could restart runserver to get the latest changes. Which is...
Ment asked 18/9, 2010 at 17:36

10

If you are in the view and want to retrieve the app name using Python ( the app name will be used for further logic ), how would you do it ?
Unprofitable asked 14/5, 2011 at 6:32

3

Solved

File "/usr/local/lib/python3.7/dist-packages/psycopg2/__init__.py", line 126, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) django.db.utils.OperationalError: FA...
Caramelize asked 8/1, 2020 at 18:16

8

Solved

Python/Django n00b moving over from javascript. Trying to add an API endpoint using Django REST Framework which I'm hoping will ultimately be able to update a User with the body of a PATCH request...
Nazarite asked 6/12, 2018 at 10:25

6

Solved

I need a per user caching. The regular view caching does unfortunately not support user-based caching. I tried the template fragment caching like this: {% load cache %} {% cache 500 "mythingy&...
Herwig asked 22/11, 2013 at 14:3

5

Solved

I'm using Django's per-view @cache_page decorator and have set a different key_prefix for each view. I've previously deleted the cache with: from django.core.cache import cache cache.clear() But w...
Reive asked 26/9, 2017 at 8:50

4

The Django docs show how to return the last page of a paginated queryset using a function-based view by catching the EmptyPage exception. What's the easiest way to achieve the same thing using gen...
Apthorp asked 27/11, 2016 at 23:41

4

I need to serve images securely to validated users only (i.e. they can't be served as static files). I currently have the following Python view in my Django project, but it seems inefficient. Any i...
Pharyngoscope asked 9/6, 2010 at 4:50

1

Solved

I have a view that is part of a page, I am using HTMX to update this view multiple times (each time is a new question, the user answers, then the next question is shown). The rest of the page does ...
Animadversion asked 28/11, 2023 at 18:0

6

Solved

I am getting the error: 'str' object has no attribute 'META' The Traceback highlights this bit of code: return render('login.html', c) Where that bit of code is in my views.py: from django.short...
Calculus asked 18/11, 2013 at 10:12

1

I have a form called DemoForm which is related to model Demo class Demo(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) ans = models.CharField(max_length=1024) and the...
Topper asked 11/9, 2019 at 7:34

2

Solved

Can Anyone please explain me what this error means?? I have done this in my views.py: class FormListView(FormMixin, ListView): def get(self, request, *args, **kwargs): # From ProcessFormMixin f...
Kepi asked 9/10, 2018 at 12:3

4

Solved

I am trying to create a formset to save records in a go. But, I keep getting the error when I submit my form. And if possible please as tell me how should I save my batch of records. My views.py: ...

2

I am trying to edit an updateview in django that has an inlineformset. Below are the model.py, forms.py, views.py, and the template files. The form is not saving, so I placed a print(actor_form) in...
Leija asked 4/10, 2018 at 12:30

2

Solved

I have a view that sets a cookie using response.set_cookie method. I would like to test if the cookie is being set in a TestCase. According to docs, the cookie should be accessible in the client ob...
Bowstring asked 24/5, 2012 at 13:42

© 2022 - 2024 — McMap. All rights reserved.