django-urls

Reverse url in reusable app that is consumed as a nested app

六眼飞鱼酱① 提交于 2019-12-08 04:11:30
问题 A similar question was answered here. My situation is slightly different though. I have created a reusable app called "categories". In my project I have an app called "dashboard". The dashboard app includes the reusable "categories" app. This causes the following to be used to reverse a url reverse('dashboard:categories:browse') However, my reusable app has no knowledge of the "dashboard" namespace. I want to be able to use the solution I linked above to reverse only the following within the

Django URL regex with variables

帅比萌擦擦* 提交于 2019-12-08 03:45:38
问题 Was hoping someone could point me in the right direction with this. I've tried nearly everything I can think of, but I can't seem to get it to work. I've got a set of URLs I'd like to match in Django: www.something.com/django/tabs/ www.something.com/django/tabs/?id=1 Basically, I want to make it so that when you just visit www.something.com/django/tabs/ it takes you to a splash page where you can browse through stuff. When you visit the second URL however, it takes you to a specific page

Django slug url in perisan 404

守給你的承諾、 提交于 2019-12-08 02:43:47
问题 I have a django url: path('question/<slug:question_slug>/add_vote/', views.AddVoteQuestionView.as_view()) It work fine with english slug but when slug is persian something like this: /question/سوال-تست/add_vote/ django url throw 404 Not Found , is there any solution to catch this perisan slug url? EDIT: I'm using django 2.1.5. It work fine with this url: re_path(r'question/(?P<question_slug>[\w-]+)/add_vote/$', views.AddVoteQuestionView.as_view()) 回答1: This is an addition to Selcuk answer

a way to have django SITEURL constant in settings.py

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-08 01:20:35
问题 I am from PHP background, and I know that constants can be accessed at most of places in a framework and I think it is same in django as well. I tried to have that URL too in django but I tried to have it from django.contrib. I tried to utilize django's Site class and imported that. But the problem is that at time of loading settings.py I can't import any django contrib. file. So how can I have SITE URL automatically that I can use anywhere, in template as well as at other places.What is the

Django Using Slug Field for Detail URL

99封情书 提交于 2019-12-07 22:30:32
I'm attempting to setup my site so that the url for my job-detail will use a slug field instead of a pk. It's telling me that it cannot find my job with the given slug (which is an int, 147). Update: After looking at the DetailView description at https://ccbv.co.uk/projects/Django/1.11/django.views.generic.detail/DetailView/ I realized there is a slug_field attribute for DetailView . My new view looks like: class JobDetailView(CacheMixin, DetailView): model = Job slug_field = 'slug' Question: urls: urlpatterns = [ url(r'^careers$', views.job_list, name='job-list'), url(r'^careers/(?P<slug>[0-9

detect the HOST domain name in django models

筅森魡賤 提交于 2019-12-07 17:01:15
问题 In my model, I want to use the domain name (HOST) I'm using in my views. In views that'd be doable, thanks to the "request" object. But how do I do this models methods? Which don't use "HttpRequest" objects? Now I'm setting a global value HOST in settings.py and using it, but that's ugly. Also, I don't really want to manage "Sites" (the Sites app) — Is there a way, I can grab the "by default" Site Host name? Thanks a lot for your help! (and sorry for my poor English) 回答1: If you're calling

Dynamic SEO-friendly URLs

家住魔仙堡 提交于 2019-12-07 09:22:48
问题 I'd like to deploy dynamic URL's for my app in two ways: when viewing available vehicle, I get a link like: http://www.url.com/2006-Acura-MDX-Technology-Package I also have a filter page, so here, the URL will change according to the filters selected like: http://www.url.com/2007-Nissan or http://www.url.com/2007-Nissan-Maxima and so on depending on the filters the user has chosen. What's the best way to go about this? EDIT 1 This now works def get_absolute_url(self): return u'%s-%s-%s-%s-%s'

Django: Downloading uploaded files

家住魔仙堡 提交于 2019-12-07 00:09:34
I have form details in this question Django: Adding files to a form gives multiple argument error How to download the uploaded file. When i go to edit view of the form, i can see uploaded file url, but its not downloading. What setting to be changed for development and production mode? Error upon clicking link: Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/media/Certificate.docx Using the URLconf defined in tiktant.urls, Django tried these URL patterns, in this order: ^ ^$ [name='home'] ^ ^login/$ [name='login'] ^ ^logout/$ [name='logout'] ^ ^logout_then_login/$

Django Context Processors: Is it possible to access current context in ContextProcessor?

北城以北 提交于 2019-12-06 21:09:20
问题 Is there a way I can access current context passed by view in custom context processor so I can add missing variable if I want rather than overriding existing variable ? What I'm trying to Achieve: I construct my URL's like this /city_slug/ and I want to check if city variable already exist in context, otherwise I want to add city to my context (may be using the last used city stored in session variable otherwise default to some city and may be even set session variable for next use.) I think

DeleteView with 2 arguements post and user

做~自己de王妃 提交于 2019-12-06 20:58:29
I have a delete view with 2 conditions "post" and "user". The user requirement is fulfilled by self.object.user = self.request.user and post requirement is fulfilled by slug = self.kwargs['slug'] (I think this may be the culprit) Are my views correct? I am new to python please forgive any silly mistakes. Views.py class ProofDelete(LoginRequiredMixin, DeleteView): model = Proof def delete(self, *args, **kwargs): return super().delete(*args, **kwargs) def get_success_url(self, *args, **kwargs): slug = self.kwargs['slug'] print(slug) obj = get_object_or_404(Post, slug=slug) url_ = obj.get