django-urls

ImproperlyConfigured at / Empty static prefix not permitted - Django

你说的曾经没有我的故事 提交于 2019-12-12 08:19:56
问题 I'm working on uploading/displaying images with Django. The website is deployed on Heroku. Following this tutorial I was able to successfully upload images. However, the images weren't being displayed in the template. I then learned that my urls.py should have this line at the end: + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) I added this to the end of my urls.py but now I'm getting this error: ImproperlyConfigured at / Empty static prefix not permitted I have MEDIA_URL and

Django - How to pass several arguments to the url template tag

一世执手 提交于 2019-12-12 07:41:00
问题 In my urls.py I have: (r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/section/(?P<slug>[-\w]+)/$', 'paper.views.issue_section_detail', {}, 'paper_issue_section_detail' ), and I'm trying to do this in a template: {% url paper_issue_section_detail issue.pub_date.year,issue.pub_date.month,issue.pub_date.day,section_li.slug %} but I get this error: TemplateSyntaxError Caught an exception while rendering: Reverse for 'paper_issue_section_detail' with arguments '(2010, 1, 22, u'business')' and

URL rendered as home_page after internationalization

Deadly 提交于 2019-12-12 05:29:10
问题 I have a Django Website that I am trying to internationalize. Until now it looked like this: Homepage: www.myhomepage.com Another page: www.myhomepage.com/content/cities Now I am trying to make it like this: Homepage: www.myhomepage.com/en www.myhomepage.com/de Another page: www.myhomepage.com/en/content/cities www.myhomepage.com/de/content/cities Following this and this, I managed to make the homepage work, so with www.myhomepage.com/en I see the homepage in English and with www.myhomepage

Can I pass non-URL definition view keyword to a view function when redirecting?

对着背影说爱祢 提交于 2019-12-12 02:52:58
问题 NoReverseMatch at /natrium/script/4c55be7f74312bfd435e4f672e83f44374a046a6aa08729aad6b0b1ab84a8274/ Reverse for 'run_details' with arguments '()' and keyword arguments '{'script_text': u'print "happy"', 'run_id': '6b2f9127071968c099673254fb3efbaf'}' not found. This is an excerpt of my views.py run_id = new_run.run_id if not run_id: raise AssertionError("bad run id") # I tried with args=[run_id, clean['script_text']] too return HttpResponseRedirect(reverse('run_details', kwargs={'run_id':run

How to get /test/?grid-view or /test/?list-view' in Django view

落爺英雄遲暮 提交于 2019-12-12 01:42:32
问题 I have a page that can be viewed by list or grid view through jQuery, but I want the URL to display what view it is -- especially when user paginate so that they don't have to reclick what they want to view -- so something like this: /test/?grid_view or /test/?list_view . I've been trying to use request.GET.get , but it doesn't seem to be working. Here is what I have so far: def test (request): grid_view = request.GET.get('grid_view') list_view = request.GET.get('list_view') if grid_view:

django media not loading

人盡茶涼 提交于 2019-12-11 18:01:31
问题 So using django for the first time and ran into this issue where the media url does not want to load/work so far my urls.py is setup like so if settings.DEBUG: urlpatterns += patterns('', (r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),) my settings.py like so PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media') MEDIA_URL = '/media/' ADMIN_MEDIA_PREFIX = 'http:/localhost:8000/admin-media/' my

how to use the category name as url suffix in Django

半腔热情 提交于 2019-12-11 15:40:19
问题 Now my url is like:https://mywebsite.com/newscategory_lists-5 I want change it to:https://mywebsite.com/categoryname Here is my model: class Category(models.Model): name = models.CharField(max_length=40) # 分类名 class Meta: verbose_name = "分类" verbose_name_plural = verbose_name def __str__(self): return self.name Here is the urls.py: path('category_lists-<int:category_pk>', views.categoryNewsList, name="category_news_list"), Here is my view.py: def categoryNewsList(request, category_pk):

How to do reverse for get_absolute_url with many to many field?

无人久伴 提交于 2019-12-11 13:37:06
问题 I have a model with many-to-many fields and I need to get an ID selected from a many to many field. I decorated a get_absolute_url method with permaling decorator. And it doesn't work. So I understand that I need to reverse the relation, it is obvious from the trace, but I do not really understand what should I do? Model: class MenuItems(models.Model): reference_value = models.CharField(max_length=255) filter_ids = models.ManyToManyField(Filter, blank = True) def __unicode__(self): return u'

Axios unable to get JSON from Django view

。_饼干妹妹 提交于 2019-12-11 10:47:55
问题 I want to implement a front-end and back-end data interaction with axios and django view. Now I have succeed in posting data to django view with code below. axios.post("{% url 'main:getCommodityInfo'%}", param, {headers:{'X-CSRFToken': this.getCookie('csrftoken')}}) .then(response=>{ console.log(response); alert("response has been caught"); }) .catch(error=>{ console.log(error); alert("connection has error") }) But when I want to return json from view to axios: def getCommodityInfo(request):

Django. How to redirect to url with fragment identifier

自作多情 提交于 2019-12-11 09:31:34
问题 For example in some cases after POST or GET request I want to redirect user not only to specific page, but to a specific part of page. What would be better: implement this in Django(reconstruct redirect url?) or implement this in javascript? 回答1: Why would you want to do it in JS? If you're redirecting to a different page already, just add #whatever to the redirect URL to go direct to the anchor. 来源: https://stackoverflow.com/questions/11053690/django-how-to-redirect-to-url-with-fragment