django-urls

Can't get the detail view of a post in a social network project

二次信任 提交于 2020-05-17 07:15:06
问题 I am building a simple social network in django. In the "home" of my social, I have the list of all posts published by all users, with author and publishing date. The publishing date have a link to a url that should return the detail view of a specific post published by a user. However, as I click on it, it shows me the list of all posts published by its author (this also works when I click on the author link of the post). So both www.mysocial.com/posts/by/ciccio/7/ and www.mysocial.com/posts

how to redirect a url with pk to url with pk and slug in django?

巧了我就是萌 提交于 2020-05-13 07:38:53
问题 when a user enters this url below www.example.com/1234 he must be redirected to www.example.com/1234/this-is-your-first-post For example, if you try this: http://stackoverflow.com/questions/15443306/ you will be redirected to http://stackoverflow.com/questions/15443306/hover-menu-in-right-side-of-fixed-div Actually it is not a redirect , it is just extending the url with slug field automatically. I want to implement this feature: Here is my models class Article(models.Model): title = models

Django checkout not accessible: Page not found (404)

不打扰是莪最后的温柔 提交于 2020-04-30 06:32:25
问题 I'm trying to develop an e-commerce site with Django. So I'm at this point where, users can add items to their cart, but when I try to proceed to checkout, for some reason, my checkout form is not displayed rather, it says: Page not found (404) I made sure that I have registered my models, and ran migrations. What is the problem? My views.py: @login_required def checkout(request): address_form = UserAddressForm(request.POST or None) if address_form.is_valid(): new_address = address_form.save

Django checkout not accessible: Page not found (404)

我怕爱的太早我们不能终老 提交于 2020-04-30 06:32:07
问题 I'm trying to develop an e-commerce site with Django. So I'm at this point where, users can add items to their cart, but when I try to proceed to checkout, for some reason, my checkout form is not displayed rather, it says: Page not found (404) I made sure that I have registered my models, and ran migrations. What is the problem? My views.py: @login_required def checkout(request): address_form = UserAddressForm(request.POST or None) if address_form.is_valid(): new_address = address_form.save

How to get parameters from current url

我的梦境 提交于 2020-03-02 09:39:08
问题 Is it possible to get an specific parameter in a url and use it in a template ? `{{ request.path }} It gets the whole url, i need only the 'pk' parameter, to make a link to another page. Thanks. 回答1: I did some experiments and find that this may help: {{ request.resolver_match.kwargs.pk }} For more info you can check this. 来源: https://stackoverflow.com/questions/40797746/how-to-get-parameters-from-current-url

Django--URL Caching Failing for Class Based Views

孤者浪人 提交于 2020-02-05 21:30:13
问题 I've built a RESTful API on top of the Django Rest Framework. The URL conf for the API is composed of class based views. I would like to cache these views, however, the following is failing. Any thoughts on why that might be and how I could change it? from django.views.decorators.cache import cache_page urlpatterns = patterns('', url(r'^dounces/?$', cache_page(60*60)(DounceListView.as_view(resource=DounceResource)), name='dounces_api'), I have the following middleware installed. 'django

How create a custom form in django with database values

余生长醉 提交于 2020-01-25 06:50:14
问题 model.py class Venue(models.Model): venue_Name = models.CharField(max_length=100) place = models.CharField(max_length=50) rent = models.IntegerField() parking_area = models.IntegerField() class Decoration(models.Model): rate = models.IntegerField() I have printed the values in database as radio buttons what i want to do is that i want to get the total sum i.e venue.rent + decoration.rate and print it in another page What shoud i give in form action I'm not that familiar with forms. html <form

Configure Django URLS.py to keep #anchors in URL after it rewrites it with a end /

一曲冷凌霜 提交于 2020-01-24 12:47:16
问题 In my django application I have my URLS.PY configured to accept requests to /community/user/id and /community/user/id/ with: url(r'^(?P<username>[\w-]+)/(?P<cardId>\d+)/$', 'singleCard.views.singleCard', name='singleCardView'), I did this as some times people will add an ending "/" and I didn't want to raise a 404. However parts of my javascript application sometime add a anchor tag in the form of: /community/user/id#anchorIuseInJavscriptToDoSomething The problem I have is Django will

_reverse_with_prefix() argument after * must be an iterable, not int

╄→尐↘猪︶ㄣ 提交于 2020-01-23 07:58:35
问题 I have used Django's reverse multiple times in the past but getting this error today which doesn't seem intuitive enough to debug: TypeError: _reverse_with_prefix() argument after * must be an iterable, not int Here's the view where I am using it: from django.urls import reverse ... ... def show_scores_url(self, obj): scores_url = reverse('get_scores', args=(obj.pk)) return format_html('<a href="' + scores_url + '">Scores</a>') ... ... 回答1: As mentioned in this comment, putting a comma at the

_reverse_with_prefix() argument after * must be an iterable, not int

余生长醉 提交于 2020-01-23 07:58:26
问题 I have used Django's reverse multiple times in the past but getting this error today which doesn't seem intuitive enough to debug: TypeError: _reverse_with_prefix() argument after * must be an iterable, not int Here's the view where I am using it: from django.urls import reverse ... ... def show_scores_url(self, obj): scores_url = reverse('get_scores', args=(obj.pk)) return format_html('<a href="' + scores_url + '">Scores</a>') ... ... 回答1: As mentioned in this comment, putting a comma at the