django-urls

Django Passing list of objects to template

巧了我就是萌 提交于 2019-12-23 21:13:09
问题 I have trouble of passing my get_profiles in the same template as r'^compose/$' here. r'^users/$' is what I'm using as a model and it works. "compose" is a function in my views.py. from django.conf.urls.defaults import * from django.views.generic.simple import redirect_to from django.views.generic.simple import direct_to_template from messages.views import * from userprofile.views import get_profiles urlpatterns = patterns('', url(r'^$', redirect_to, {'url': 'inbox/'}), url(r'^inbox/$', inbox

Django 1.5.1 'ImportError: No module named urls' when running tests

爱⌒轻易说出口 提交于 2019-12-23 18:04:31
问题 I've started project with Django 1.5 I've the following urls, views, and tests of the profile app. When I browse localhost:8000/profiles it works just fine but when I run test for profile app ./manage.py test profile it fails with the following exception File "<stdlib>/site-packages/django/core/urlresolvers.py", line 342, in RegexURLResolver.urlconf_module self = <RegexURLResolver 'yoda.urls' (None:None) ^/> 340 return self._urlconf_module 341 except AttributeError: --> 342 self._urlconf

Newbie Django urls, views, and templates - how can this incredibly simple django project possibly be failing?

我是研究僧i 提交于 2019-12-23 05:32:09
问题 When the user lands at http://127.0.0.1:8000/ I would like to display an html page that says "welcome." When the user goes http://127.0.0.1:8000/time/ I would like to display the current time. I have followed instructions to the t and dotted every i. My settings are below. Why do I continue to get a TemplateDoesNotExist error? views.py from django.template.loader import get_template from django.shortcuts import render import datetime def current_datetime(request): now = datetime.datetime.now(

Django Using Slug Field for Detail URL

只谈情不闲聊 提交于 2019-12-23 03:26:48
问题 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:

Django NameError urls.py

你说的曾经没有我的故事 提交于 2019-12-23 03:04:14
问题 Im getting a name error: name sitemaps is not defined from my urls.py when I try to integrate sitemaps with my application. From my urls.py: from django.contrib.sitemaps import Sitemap (r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}), Is there something wrong with this regular expression from my urls.py? Or is there another problem going on? Thanks for your input 回答1: Generally you will do something like this - from django.contrib.sitemaps import Sitemap,

Django NameError urls.py

老子叫甜甜 提交于 2019-12-23 03:03:18
问题 Im getting a name error: name sitemaps is not defined from my urls.py when I try to integrate sitemaps with my application. From my urls.py: from django.contrib.sitemaps import Sitemap (r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}), Is there something wrong with this regular expression from my urls.py? Or is there another problem going on? Thanks for your input 回答1: Generally you will do something like this - from django.contrib.sitemaps import Sitemap,

Using both sort & filter on a QuerySet

拥有回忆 提交于 2019-12-23 02:45:11
问题 I have a list of userprofiles that I want to be able to sort and filter. I have been able to do this manually, by manually typing in the URLs, but I haven't been able to code the template page to allow the persistence of a previously-applied filter or sort. Here is the url and template code that I currently have -- # in urls url(r'^talent/filter\:(?P<position>[A-Za-z]+)/sort\:(?P<sort>[A-Za-z]+)$', 'talent_filter', name='talent_filter_sort'), url(r'^talent/filter\:(?P<position>[A-Za-z]+)/$',

Django Postman implementation for sending messages

徘徊边缘 提交于 2019-12-23 01:34:48
问题 I am trying to use the Django-Postman framework to send messages between users in Django 2.0 . I have installed the app and made the necessary changes as mentioned in the docs of the framework. However when i try to go the the message urls I get a blank page (like this screenshot): Here is what I have done so far: Installed django-postman In settings.py INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib

Django two views on a webpage

99封情书 提交于 2019-12-22 11:28:11
问题 Hello and thank you in advance, I am very much a Django/Python noobie. I just need guidance, not necessarily answers. I have read all the pertinent documentation and I can't seem to find a concise example of what I am trying to do. I have two views, one is a form and the other is a view that lists data contained in a database table. I am trying to display both these views on the same webpage page that is called by the user going to one URL listed in the URLS.py file. I am sure this is

Outputing text from urls.py in Django

一曲冷凌霜 提交于 2019-12-22 08:23:20
问题 Is there any way I can simply output text (not HTML) from urls.py instead of calling a function (in views.py or otherwise)? urlpatterns = patterns('', url(r'^$', "Hello World"), ) 回答1: No, definitly. A url must map a pattern to a callable, and this callable must accept a HttpRequest as first argument and return a HttpResponse . The closer thing you could do would be to map the pattern to a lambda (anonymous function), ie: from django.http import HttpResponse urlpatterns = patterns('', url(r'^