django-urls

django, name 'IndexView' is not defined

孤人 提交于 2019-12-14 01:29:47
问题 I am following this tutorial. At the moment I am at this point but when I start my server with python manage.py runserver 0.0.0.0:8000 and open the url in my browser, I receive following Error: name 'IndexView' is not defined This is my urls.py from django.conf.urls import include, url from django.contrib import admin from django.conf.urls import patterns from rest_framework_nested import routers from authentication.views import AccountViewSet router = routers.SimpleRouter() router.register(r

Modify address in Django middleware

…衆ロ難τιáo~ 提交于 2019-12-13 14:30:04
问题 I don't know if it's possible but I'd like to add few parameters at the end of the URL using middleware. Can it be done without redirect after modyfing requested URL? ie. user clicks: .../some_link and middleware rewrites it to: .../some_link?par1=1&par2=2 Other way is to modify reponse and replace every HTML link but it's not something I'd like to do. Thanks 回答1: I think this really depends on your problem and what exactly you are trying to do. You cannot change the URL without redirecting

Django: Downloading uploaded files

我的梦境 提交于 2019-12-13 12:44:52
问题 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

How to Call loggedin username in Django url

烂漫一生 提交于 2019-12-13 04:34:50
问题 I have djando login url, after user loggedin, its getting called as bellow: (r'^$', RedirectView.as_view(url= '/home/')), I want to pass loggedin username in above url , such as (r'^$', RedirectView.as_view(url= '<username>')), Please suggest. 回答1: Would recommend deriving the RedirectView class in a view, like this: class HomeRedirectView(RedirectView): pattern_name = 'home' def get_redirect_url(self, *args, **kwargs): return "/user/{}/".format(self.request.user) In urls.py : (r'^$',

How to write pattern for all other urls that basically goes for not found in django?

社会主义新天地 提交于 2019-12-13 04:24:14
问题 I tried this, url ('', views.notfound, name='notfound') But seems it doesn't work properly, for example, I have another url pattern define, url(r'^login/$', views.login, name='login'), So, if I go for http://example.com/login/ , this works, but if i go for http://example.com/login/?help=1 , then it falls into notfound category. How can I handle that? 回答1: If you just want to create a page that is displayed when a URL is not found (i.e. a Http404 exception is thrown) you can create a template

Objects and attribute errors on browser, after server runs

牧云@^-^@ 提交于 2019-12-13 03:25:55
问题 I'm new to Django and I'm working on an app that display the objects of a primary key. The server runs fine but I get an error on the browser that says: 'master_courses' objects has no attribute 'masterCourses_slug' The code looks like this: from django.shortcuts import render, redirect from .models import master_courses, course_category, course_series def single_slug(requests, single_slug): categories = [c.course_slug for c in course_category.objects.all()] if single_slug in categories:

The callback function object in Django URLconf is not called

流过昼夜 提交于 2019-12-13 03:07:52
问题 I am learing Django on Django at a glance | Django documentation | Django When introducing URLconf It reads: To design URLs for an app, you create a Python module called a URLconf. A table of contents for your app, it contains a simple mapping between URL patterns and Python callback functions. Nevertheless, a callback function is not called. mysite/news/urls.py from django.conf.urls import url from . import views urlpatterns = [ url(r'^articles/([0-9]{4})/$', views.year_archive), ] print(

get_absolute_url with parameters

笑着哭i 提交于 2019-12-12 20:14:27
问题 My urls.py : urlpatterns = [ ... url(r'^profile/$', profile.profile, name='profile'), ] My model : class Reg(models.Model): name = models.CharField(max_length=32, primary_key=True) user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.PROTECT, related_name='%(app_label)s_%(class)s_reg', null=True) ... def get_absolute_url(self): return reverse('core:profile', ???) My views : @login_required def profile(request): context_dict = {} u = User.objects.get(username=request.user)

Adding extra filter to polls urls.py causes tests to fail

谁都会走 提交于 2019-12-12 19:45:16
问题 Following the tutorial at djangoproject, I have tried to have urls.py filter out the polls with no choices with the urlpattern below. urlpatterns = patterns('', url(r'^$', ListView.as_view( queryset=Poll.objects.filter(choice__choice_text__isnull=False) \ .filter(pub_date__lte=timezone.now) \ .order_by('-pub_date')[:5], context_object_name='latest_polls', template_name='polls/index.html'), name='index'), url(r'^(?P<pk>\d+)/$', DetailView.as_view( queryset=Poll.objects.filter(choice__choice

One url for two different views

守給你的承諾、 提交于 2019-12-12 09:25:56
问题 I'm developing a site that have two types of User, and the project's owners want two different home (templates) after the user is authenticated, so, I tried this: url # home a url(r'^home/$', HomeAView.as_view(), name='home-a'), # home b url(r'^home/$', HomeBView.as_view(), name='home-b'), And some like that at into my log_in view: if user.typeUser == "HA": print('Go to Home A') return redirect(reverse('sesion:home-a')) else: print('Go to Home B') return redirect(reverse('sesion:home-b')) So