django-urls

django media url tag

坚强是说给别人听的谎言 提交于 2019-11-29 18:22:47
问题 Does django have media tag similar to static and url and how to setup it? {% static 'styles/boo.css' %} {% url 'some_app:some_name' %} Is this possible: {% media 'what here' %}? How to setup it? 回答1: You need {% get_media_prefix %}. The way to set it up is explained in the docs: you have to set the MEDIA_ROOT and the MEDIA_URL in your settings and add the MEDIA_URL to your urls.py . 回答2: No there is no media template tag. Having set MEDIA_ROOT and MEDIA_URL you can use a media file in a

Django HttpResponseRedirect

大兔子大兔子 提交于 2019-11-29 17:00:14
问题 I have created a basic contact form, and when the user submits information, it should redirect to the "Thank You" page. views.py : def contact(request): # if no errors... return HttpResponseRedirect('/thanks/') urls.py : (r'^contact/$', contact), (r'^contact/thanks/$', contact_thanks), Both pages work at the hard-coded URL. However, when I submit the form on /contact/ it redirects to /contact (no ending slash), which is a nonexistent page (either a 404 or an error page telling me I need a

django url parameters before include url with namespace

試著忘記壹切 提交于 2019-11-29 15:55:27
In my last question I asked how to get urls working for parameter before included urls.py and it worked. Django {% url %} when urls with parameters like: url(r'^foo/<parameter>/$', include(some.urls)) Now I want to use the same included urls.py with namespaces . urls.py urlpatterns = patterns('', url(r'^/foo/(?P<parameter_1>\d+)/', include('bar.urls', namespace='foo', app_name='foo')), ) bar.urls.py urlpatterns = patterns('', url(r'^/bar/$', 'bar.views.index', name='bar'), url(r'^/bar/(?P<parameter_2>\d+)/$', 'bar.views.detail', name='bar_detail'), ) To get the url in template I use: 1. {% url

The current URL, app/, didn't match any of these

自闭症网瘾萝莉.ら 提交于 2019-11-29 14:05:26
I'm a newbie in Django and just started looking at it before a day by installing Django 1.10 on my local. I've followed all the instructions of this link https://docs.djangoproject.com/en/dev/intro/tutorial01/ . However I'm continuously getting this error: Page not found (404) Request Method: GET Request URL: http://127.0.0.1:8000/polls/ Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^admin/ The current URL, polls/, didn't match any of these. I've created polls app to getting started. To make a start, I went with view.py, here is the code: polls/views

Django/python: 'function' object has no attribute 'as_view'

只愿长相守 提交于 2019-11-29 12:43:18
问题 I am trying to create a list_view for a model queryset. When running my server, it returns : attribute error - 'function' object has no attribute 'as_view'. I would appreciate helping me in solve this. Here's my code: Views.py: @login_required class live_bids(ListView): model = Post template_name = 'loggedin_load/live_bids.html' def get_queryset(self): return Post.objects.all().prefetch_related('bids').filter(user=self.request.user) urls.py: url(r'^live_bids/$', live_bids.as_view()), 回答1: You

Django: Arbitrary number of unnamed urls.py parameters

别说谁变了你拦得住时间么 提交于 2019-11-29 11:59:33
问题 I have a Django model with a large number of fields and 20000+ table rows. To facilitate human readable URLs and the ability to break down the large list into arbitrary sublists, I would like to have a URL that looks like this: /browse/<name1>/<value1>/<name2>/<value2>/ .... etc .... where 'name' maps to a model attribute and 'value' is the search criteria for that attribute. Each "name" will be treated like a category to return subsets of the model instances where the categories match. Now,

How do I pass variables from one view to another and render with the last view's URL in Django?

只愿长相守 提交于 2019-11-29 10:42:35
I'm building a student management system using Django. In this code, The user search for a student with the encrypted query name=StudentName&grade=Grade&id=StudentID&phone=ParentPhoneNumber&report=StudentReportNumber , that is extracted with the decrypt() method. Here are the two methods, the one which process the query and the one which shows the student profile. No data from the query is saved to the database, but will be used to query the student details from the database. def process_query(request): # process the query from the url /?details={{ some hashes here }} if request.method == 'GET

Pass url argument to ListView queryset

喜你入骨 提交于 2019-11-29 07:12:38
问题 models.py class Lab(Model): acronym = CharField(max_length=10) class Message(Model): lab = ForeignKey(Lab) urls.py urlpatterns = patterns('', url(r'^(?P<lab>\w+)/$', ListView.as_view( queryset=Message.objects.filter(lab__acronym='') )), ) I want to pass the lab keyword argument to the ListView queryset. That means if lab equals to TEST , the resulting queryset will be Message.objects.filter(lab__acronym='TEST') . How can I do that? 回答1: You need to write your own view for that and then just

No module named backends.default.urls

╄→гoц情女王★ 提交于 2019-11-29 05:47:29
So I've installed django-registration through easy_install. I'm following a quick start guide and I'm trying to setup my urlConf, however it says module named backends.defauls.urls is not found. What might be the problem ? import registration (r'^accounts/', include('registration.backends.default.urls')), Is the registration module in your PYTHONPATH ? (not my solution, but since it was hidden in a comment) You need to use use include('registration.urls') , instead of include('registration.backends.default.urls') I'd suggest always getting django-registration from Bitbucket: https://bitbucket

How to access url hash/fragment from a Django Request object

烂漫一生 提交于 2019-11-29 05:30:30
问题 As in the title: how can I access the url hash/fragment (the part following the dash # ) from a Django view and so, I suppose, from a Django Request object? I've not found enough information on the documentation here available: http://docs.djangoproject.com/en/dev/ref/request-response/ P.S. Suppose that the fragment part is sent to the server (it is so in my specific case since it's not a browser to send the request). 回答1: This is not sent to the server, by definition. From URI References: