django-views

How do I pass a list from one view to another in Django?

大兔子大兔子 提交于 2021-01-27 06:31:00
问题 I've been scouring StackOverflow, but I haven't found an answer to this that works for me. I am relatively new to Python and Django, so maybe I'm thinking about it wrong. To make a simple example, imagine two views with different associated URLs. This is not supposed to be perfect code. I'm just trying to figure out how to get a variable-length list of items from view 1 into view 2. I don't see a way to do it via the URL because the list may be variably long. Shouldn't this be extremely easy

How do I pass a list from one view to another in Django?

℡╲_俬逩灬. 提交于 2021-01-27 06:30:26
问题 I've been scouring StackOverflow, but I haven't found an answer to this that works for me. I am relatively new to Python and Django, so maybe I'm thinking about it wrong. To make a simple example, imagine two views with different associated URLs. This is not supposed to be perfect code. I'm just trying to figure out how to get a variable-length list of items from view 1 into view 2. I don't see a way to do it via the URL because the list may be variably long. Shouldn't this be extremely easy

Class Based Generic Views and DRY

折月煮酒 提交于 2021-01-23 00:33:33
问题 I'm implementing class based views in Django 1.3 and I find myself in this scenario where my CreateView, UpdateView and DeleteView are almost identical. Is there a way to implement this with only a single view CreateUpdateView or something like that or is this the standard way to implement CBGV's? Also, in ThingyAdd I haven't specified the model like I have in ThingyEdit, yet they both function fine. I'm making the assumption that the model is implied/picked-up by the model defined in the

Class Based Generic Views and DRY

我们两清 提交于 2021-01-23 00:33:26
问题 I'm implementing class based views in Django 1.3 and I find myself in this scenario where my CreateView, UpdateView and DeleteView are almost identical. Is there a way to implement this with only a single view CreateUpdateView or something like that or is this the standard way to implement CBGV's? Also, in ThingyAdd I haven't specified the model like I have in ThingyEdit, yet they both function fine. I'm making the assumption that the model is implied/picked-up by the model defined in the

Class Based Generic Views and DRY

ぐ巨炮叔叔 提交于 2021-01-23 00:33:19
问题 I'm implementing class based views in Django 1.3 and I find myself in this scenario where my CreateView, UpdateView and DeleteView are almost identical. Is there a way to implement this with only a single view CreateUpdateView or something like that or is this the standard way to implement CBGV's? Also, in ThingyAdd I haven't specified the model like I have in ThingyEdit, yet they both function fine. I'm making the assumption that the model is implied/picked-up by the model defined in the

Django: Passing object from template to views

北战南征 提交于 2021-01-21 11:21:18
问题 I want to use the same template to view information about each of my database objects. I would like to be able to click on each element in the list and have it link me to a page with info about it. I'm thinking there's an easier way than making a view for each unique object. I'm listing all of my database objects on my list.html like this: {% for instance in object_info %} <li><a href="object">{{ instance.name }}</a></li> {% endfor %} My views.py has this view: def object_view(request): data

Django: Passing object from template to views

社会主义新天地 提交于 2021-01-21 11:19:07
问题 I want to use the same template to view information about each of my database objects. I would like to be able to click on each element in the list and have it link me to a page with info about it. I'm thinking there's an easier way than making a view for each unique object. I'm listing all of my database objects on my list.html like this: {% for instance in object_info %} <li><a href="object">{{ instance.name }}</a></li> {% endfor %} My views.py has this view: def object_view(request): data

NoReverseMatch at / Reverse for 'post_detail' with keyword arguments '{'pk': ''}' not found

孤人 提交于 2021-01-20 13:12:09
问题 I've been trying to get this app to work, I run: python manage.py runserver - & everything was fine, I was able to see the website, login as a superuser, make a comment, however in trying to view the post I started to get an error. Now, if I just go to the site, i get an error. I get this error message: File "/Users/homepage/opt/anaconda3/envs/MyDjangoEnv/lib/python3.8/site-packages/django/urls/resolvers.py", line 685, in _reverse_with _prefix raise NoReverseMatch(msg) django.urls.exceptions

Pass dictionary data to Django view

白昼怎懂夜的黑 提交于 2021-01-07 06:43:50
问题 I'm confused on how to set up/call my url to pass a dictionary of data from my template to my view. I'm getting an error "NoReverseMatch at /categories/academy/" How can I pass data_dict , which is a dictionary, to my view? template.html <a href="{% url 'polls:request_access' data_dict %}" class="btn btn-green btn-sm"><i class="fa fa-plus"></i> Join Group</a> urls.py # the category_slug in this case is "academy", see the error I mentioned above url(r'^categories/(?P<category_slug>[-\w]+)

Pass dictionary data to Django view

喜夏-厌秋 提交于 2021-01-07 06:43:44
问题 I'm confused on how to set up/call my url to pass a dictionary of data from my template to my view. I'm getting an error "NoReverseMatch at /categories/academy/" How can I pass data_dict , which is a dictionary, to my view? template.html <a href="{% url 'polls:request_access' data_dict %}" class="btn btn-green btn-sm"><i class="fa fa-plus"></i> Join Group</a> urls.py # the category_slug in this case is "academy", see the error I mentioned above url(r'^categories/(?P<category_slug>[-\w]+)