django-views

Load CSS/images in Django

做~自己de王妃 提交于 2020-01-05 02:31:08
问题 I've read the official Django Docs and many other posts here in SO. Still I'm unable to figure out the way to load my CSS files in HTML pages. I'm running Django 1.4 . Here is my whole structure of mysite project having auth as the app. mysite/ manage.py settings.py __init__.py urls.py auth/ __init__.py forms.py models.py views.py templates/ index.html home.html media/ common.css How can I load my common.css file in index and home template files? 回答1: Take a look at static files : https:/

Display forms choice in template-Django

一世执手 提交于 2020-01-04 14:08:30
问题 On the template, when I call person.health_issue, I am getting '1','2' instead of 'Abdominal pain','Anaphylaxis'. How to display the value ('Abdominal pain','Anaphylaxis') instead of the code(1 or2 etc). I tried with this also {{ person.get_health_issue_display }} in template,it is not displayed anything. forms.py HEALTH_USSUES = ( ('1', 'Abdominal pain'), ('2', 'Anaphylaxis'), ('3', 'Asthma'), ('4', 'Bruising'), ('5', 'Chest pains'), ('6', 'Coughs or Colds') ) class PersonActionsForm(forms

how do i create a table from a dict using django-tables2

孤街浪徒 提交于 2020-01-04 12:46:16
问题 I have a list of dict that look like this: [set([u'meal', '0:08:35.882945']), set([0, u'personal']), set([0, u'sleep']), set([0, u'transport']), set([0, u'work'])] That I made from : [u'meal',u'personal', u'sleep', u'transport', u'work'] ['0:08:35.882945', 0, 0, 0, 0] With this command: nob = [{m,n} for m,n in zip(cats,tot3)] How can I turn this into a django-tables2 table? I tried this : # tables.py class Small_table (tables.Table): category = tables.Column(verbose_name="category") class

Django REST and ModelViewSet filtering

橙三吉。 提交于 2020-01-04 09:03:37
问题 I was previously using APIViews such as the following: views.py class AllProgramsApi(APIView): def get(self, request): user = self.request.user userprograms = Program.objects.filter(user=user) serializer = ProgramSerializer(userprograms, many=True) return Response(serializer.data) here's my model: class Program(models.Model): program_name = models.CharField(max_length=50) program_description = models.CharField(max_length=250) cycles = models.ManyToManyField(Cycle) is_favourite = models

How to populate html table with info from list in django

跟風遠走 提交于 2020-01-04 05:12:34
问题 I want to populate, in my django application, my table from base.html with the results from urlparse.py (this returns a list of 20 URLs from a site). models.py from django.db import models from django.utils.encoding import smart_unicode # Create your models here. urlparse.py import HTMLParser, urllib2 class MyHTMLParser(HTMLParser.HTMLParser): site_list = [] def reset(self): HTMLParser.HTMLParser.reset(self) self.in_a = False self.next_link_text_pair = None def handle_starttag(self, tag,

How to populate html table with info from list in django

南楼画角 提交于 2020-01-04 05:12:10
问题 I want to populate, in my django application, my table from base.html with the results from urlparse.py (this returns a list of 20 URLs from a site). models.py from django.db import models from django.utils.encoding import smart_unicode # Create your models here. urlparse.py import HTMLParser, urllib2 class MyHTMLParser(HTMLParser.HTMLParser): site_list = [] def reset(self): HTMLParser.HTMLParser.reset(self) self.in_a = False self.next_link_text_pair = None def handle_starttag(self, tag,

How to read the json file of a dynamical way in relation to their size structure

烈酒焚心 提交于 2020-01-04 02:15:15
问题 I have the following JSON file named ProcessedMetrics.json which is necessary read for send their values to some template: { "paciente": { "id": 1234, "nombre": "Pablo Andrés Agudelo Marenco", "sesion": { "id": 12345, "juego": [ { "nombre": "bonzo", "nivel": [ { "id": 1234, "nombre": "caida libre", "segmento": [ { "id": 12345, "nombre": "Hombro", "movimiento": [ { "id": 1234, "nombre": "flexion", "metricas": [ { "min": 12, "max": 34, "media": 23, "moda": 20 } ] } ] } ], "___léeme___": "El

How do I modify the file upload handlers in a class based View with CSRF middleware?

孤人 提交于 2020-01-03 19:33:49
问题 In my Django project I will have to modify the tuple of file upload handlers "on the fly" as documented, to have the ability to modify the file stream as it is being uploaded. I need this "on the fly", because I have to provide the handler some data from the View (see setup() method in the code below). The documentation also mentions how to take care of doing this if you use CSRF protection. This is special because the CSRF protection middleware accesses the POST data in the request resulting

Django: resolve(request.path).app_name does not return app name

无人久伴 提交于 2020-01-03 18:14:52
问题 I'm trying to access the current app name from a view or template. In other SO answers How to get an app name using python in django and How to get current application in Django I found that resolve(request.path).app_name should return the current app name. But in my case it alwas returns "None". I'm using Django 1.3. 回答1: For that to work, you have to pass a app_name parameter when including your urls: #urls.py urlpatterns = patterns('', (r'^manufacturers/', include('manufacturers.urls', app

return response in django rest-framework

会有一股神秘感。 提交于 2020-01-03 14:01:11
问题 I am writing an app in django rest-framework: My views.py: class tagList(generics.ListCreateAPIView,APIView): model = tags serializer_class = getAllTagsDetailSerializer def get_queryset(self): print "q1" print self.request.QUERY_PARAMS.get('tag', None) print self.request.user print "q1" if tags.objects.filter(tag='burger')!= None: return tags.objects.filter(tag='burger') else: content = {'please move along': 'nothing to see here'} return Response(content, status=status.HTTP_404_NOT_FOUND) I