django-urls

include() got an unexpected keyword argument 'app_name'

五迷三道 提交于 2021-02-07 06:06:43
问题 i am making a blog application for my website with django-2.0 when i run server i see the following error File "C:\Users\User\Desktop\djite\djite\djite\urls.py", line 7, in <module> url(r'^blog/', include('blog.urls', namespace='blog', app_name='blog')), TypeError: include() got an unexpected keyword argument 'app_name' here is my main urls.py from django.contrib import admin from django.conf.urls import url,include urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^blog/', include(

get app name from url in django

一曲冷凌霜 提交于 2021-01-28 07:53:40
问题 I know how to get the url name with url resolve in django. I want to treat all requests that come from a certain app similarly so I think I would do this by getting the app name from the url. How can I do this? 回答1: path you would be a headache as you would have to apply a lot of splits. A better way to do this is: request.resolver_match which contains : {'app_name': '', '_func_path': 'app_name.views.ClassName', 'args': (), 'func': , 'url_name': 'url-for-class', 'namespace': '', 'kwargs': {},

Django reverse using kwargs

偶尔善良 提交于 2021-01-27 16:44:52
问题 Say, in the post method of my registration class, I want to redirect the user to the login page if the user is already registered, simple enough. class Register(View): ... def post(self, request): # Some code to check if the email address is already in the db message = {'message': 'You are already a member and registered the project. Please just log-in', 'registration_date': the_registered_date}# The form with the filled-in data is returned return HttpResponseRedirect(reverse('accounts:login'

changing admin site url

孤人 提交于 2021-01-27 08:01:19
问题 Is there a way to change the url to open the admin site in django? I don't want to use the default /admin url. I am new to django so please try giving a bit more detailed information. 回答1: In urls.py, change the line that reads: (r'^admin/(.*)', admin.site.root), to something like: (r'^new_admin/(.*)', admin.site.root), so now instead of http://example.com/admin you'd use http://example.com/new_admin 回答2: Sure, the file urls.py in the root of your project maps URLs to handlers. Just change

changing admin site url

给你一囗甜甜゛ 提交于 2021-01-27 08:00:53
问题 Is there a way to change the url to open the admin site in django? I don't want to use the default /admin url. I am new to django so please try giving a bit more detailed information. 回答1: In urls.py, change the line that reads: (r'^admin/(.*)', admin.site.root), to something like: (r'^new_admin/(.*)', admin.site.root), so now instead of http://example.com/admin you'd use http://example.com/new_admin 回答2: Sure, the file urls.py in the root of your project maps URLs to handlers. Just change

Django url that captures yyyy-mm-dd date

夙愿已清 提交于 2021-01-14 16:36:13
问题 How do you capture a url that contains yyyy-mm-dd in Django. So like www.mydomain.com/2011-02-12. I tried: url(r'^(?P<date>\d{4}-\d{2}-\d{2})/$', views.index, name='index'), But, the server says page not found. 回答1: You should have a group name in the url pattern: url(r'^(?P<date>\d{4}-\d{2}-\d{2})/$', views.index, name='index'), # ^^^^ Also pay attention to the trailing slash in the url: www.mydomain.com/2011-02-12/ . If you don't want a slash in the url, you can remove it from the pattern.

Django url that captures yyyy-mm-dd date

醉酒当歌 提交于 2021-01-14 16:33:11
问题 How do you capture a url that contains yyyy-mm-dd in Django. So like www.mydomain.com/2011-02-12. I tried: url(r'^(?P<date>\d{4}-\d{2}-\d{2})/$', views.index, name='index'), But, the server says page not found. 回答1: You should have a group name in the url pattern: url(r'^(?P<date>\d{4}-\d{2}-\d{2})/$', views.index, name='index'), # ^^^^ Also pay attention to the trailing slash in the url: www.mydomain.com/2011-02-12/ . If you don't want a slash in the url, you can remove it from the pattern.

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]+)

how to have options in urls in django 2.0

旧街凉风 提交于 2021-01-02 20:22:49
问题 In Django 1 I used to have url choices like this: url('meeting/(?P<action>edit|delete)/', views.meeting_view, name='meeting'), How I do this in Django 2.0 with the <> syntax: Maybe something like this? path('meeting/(<action:edit|delete>)/', views.meeting_view, name='meeting'), 回答1: If I understand the documentation, your first syntax should work right out-of-the-box. Anyway here's how you could do with the new syntax: First file = make a Python package converters and add edit_or_delete.py