django

Django Global base.html template

纵饮孤独 提交于 2021-02-18 10:59:19
问题 I am new to Django. I am using Django 1.8.6 with Python 2.7. I am trying to use a base.html template that can be used globaly through out the entire site, where every app and access it. Here is my test site's current structure: twms polls migrations static templates project migrations static templates project index.html tmws static templates tmws base.html Here is the code for project/templates/project/index.html {% extends 'tmws/base.html' %} {% block content %} <h1>Projects</h1> <ul> {% for

python oauthlib: in escape ValueError “Only unicode objects are escapable”

被刻印的时光 ゝ 提交于 2021-02-18 10:51:34
问题 I'm using python-social-auth to login with social networks from my Django application. On my local machine everything works fine, but when I deploy to a server I get the following error: oauthlib.oauth1.rfc5849.utils in escape ValueError: Only unicode objects are escapable. Got None of type <type 'NoneType'>. Stacktrace: File "django/core/handlers/base.py", line 112, in get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "social/apps/django_app/utils.py",

GAE don't see gunicorn, but it is already installed

拈花ヽ惹草 提交于 2021-02-18 10:23:09
问题 I am trying to deploy Django app with Google App Engine. My app.yaml file: # [START runtime] runtime: python api_version: 1 threadsafe: true env: flex entrypoint: gunicorn -b :$PORT wsgi runtime_config: python_version: 3.4 env_variables: CLOUDSQL_CONNECTION_NAME: ugram-mysql CLOUDSQL_USER: root handlers: - url: / script: wsgi.application # [END runtime] But when I run gcloud app deploy , app deploy is running (5 minutes), but I get an error: Updating service [default]...failed. ERROR: (gcloud

Django: Want to display an empty field as blank rather displaying None

一笑奈何 提交于 2021-02-18 08:53:46
问题 I have a template called client_details.html that displays user , note and datetime . Now sometimes, a client may not have an entry for user, note and datetime. What my program will do instead is display None if these fields are empty. I do not want the to display None. If a field has no value I don't want to see any value e.g. let it be blank if possible instead of displaying None. views.py @login_required def get_client(request, client_id = 0): client = None try: client = models.Client

Django partial template responses

对着背影说爱祢 提交于 2021-02-18 08:15:32
问题 Is it considered correct/ are there any pitfalls in returning partial templates to ajax POST requests? For example: if request.is_ajax: # response is just the form return render(request, 'contact/fields.html', {'form':form}) 回答1: The most typical approach is returning JSON and then contructing whatever HTML you need client-side from the JSON data. However, it could be argued that this is mixing presentation with behavior and it would be better to clearly separate out the HTML. On the flip

AngularJS Upload and Post Multiple Files

放肆的年华 提交于 2021-02-18 08:15:18
问题 So ultimately, what I'm doing is trying to upload and post multiple files to a Django backend using AngularJS. I can post a single file, but it seems like when a FileList object is put in the $http.post data field, the backend no longer detects any files in the POST request. Here's what the html looks like: <form enctype="multipart/form-data" action="upload" method="POST"> <div class="form-group"> <span class="btn btn-info btn-file"> <i class="glyphicon glyphicon-file"></i> Browse <input

Hiding settings.py passwords for Heroku Django deployment

眉间皱痕 提交于 2021-02-18 07:51:41
问题 I have sensitive data (database passwords) in settings.py and I was advised to upload my Django project to a github repository before pushing it to Heroku on their "Getting Started with Django on Heroku". If I put settings.py in .gitignore, then presumably it won't get deployed with my project. How can I prevent settings.py from being exposed but still get it deployed with my project ? 回答1: You can use environment variables (with heroku config:add SECRET=my-secret ) to setup sensitive data

Django nested QuerySets

ぐ巨炮叔叔 提交于 2021-02-18 07:32:00
问题 I have a Django data model like this (data fields omitted): class Atom(Model): pass class State(Model): atom = ForeignKey(Atom) class Transition(Model): atom = ForeignKey(Atom) upstate = ForeignKey(State,related_name='uptrans') lostate = ForeignKey(State,related_name='lotrans') When I query, the fields to be restricted can be in either model, so it is easiest to query on Transition.objects.filter(...) since all fields in the other models can be reached through the foreign keys. Let's call the

Django nested QuerySets

回眸只為那壹抹淺笑 提交于 2021-02-18 07:31:16
问题 I have a Django data model like this (data fields omitted): class Atom(Model): pass class State(Model): atom = ForeignKey(Atom) class Transition(Model): atom = ForeignKey(Atom) upstate = ForeignKey(State,related_name='uptrans') lostate = ForeignKey(State,related_name='lotrans') When I query, the fields to be restricted can be in either model, so it is easiest to query on Transition.objects.filter(...) since all fields in the other models can be reached through the foreign keys. Let's call the

django 1.3 UserProfile matching query does not exist

a 夏天 提交于 2021-02-18 07:09:10
问题 I have a small problem with User model, the model looks like this: #! -*- coding: utf-8 -*- from django.db import models from django.contrib.auth.models import User class UserProfile(models.Model): url = models.URLField(max_length = 70, blank = True, verbose_name = 'WWW') home_address = models.TextField(blank = True, verbose_name = 'Home Adress') user = models.ForeignKey(User, blank = True, unique = True) def __unicode__(self): return '%s' %(self.user) When I open a django-shell and first