天道酬勤,学无止境

django

DRF Viewset remove permission for detail route

I have a basic Viewset: class UsersViewSet(viewsets.ModelViewSet): permission_classes = (OnlyStaff,) queryset = User.objects.all() serializer_class = UserSerializer It is bind to the /api/users/ endpoint. I want to create a user profile page, so I need only a particular user, so I can retrieve it from /api/users/<id>/, but the problem is that I want /api/users/<id>/ to be allowed to anyone, but /api/users/ to keep its permission OnlyStaff, so no one can have access to the full list of users. Note: Perhaps it's not such a good implementation, since anyone could brute force the data incremeting

2021-06-15 18:13:05    分类:问答    django   django-rest-framework   django-permissions

Django i18n not recognizing language files

On Django 1.4, I want to have two languages in my site, turkish('tr') and english('en'). This is my current setup: settings.py: USE_I18N = True LANGUAGES = ( ('en', 'English'), ('tr', 'Turkish'), ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.locale.LocaleMiddleware', # I have locale middleware 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', ) LOCALE_PATHS = ( '/myproject/locale/', ) And

2021-06-15 17:02:13    分类:问答    django   internationalization   translation

Cannot import settings; not on system path

I'm trying to get Django working using virtualenv. I already got the hello world page online. However, there seems to be something wrong now because most of my commands give me the same error about myProject.settings (myenv)user@mint /opt/myenv/myProject $ python manage.py startapp polls Traceback (most recent call last): File "manage.py", line 13, in <module> execute_from_command_line(sys.argv) File "/opt/myenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line utility.execute() File "/opt/myenv/local/lib/python2.7/site-packages

2021-06-15 17:00:22    分类:问答    python   django

How can I configure allowed number of GET parameter characters in uWSGI?

I am running Django with nginx + uWSGI. Having just moved from local dev to a staging server, I have discovered that a particular GET request we make has a long query string. Trying to debug, it seems that uWSGI is not accepting this query string based on length - I can pass short strings and it works, over a certain length I start getting 502 bad gateway errors. I couldn't find anything about this on the uWSGI site or via google searching. Does anyone know what could be the issue?

2021-06-15 16:57:15    分类:问答    django   nginx   uwsgi

Django OneToOneField to multiple models

Suppose we have a base model: class BaseModel(models.Model): pass with some subclasses: class Submodel1(BaseModel): some_field = models.TextField() ... class Submodel9(BaseModel): another_field = models.TextField() Each submodel is defined in its own Django app. New apps with new submodels can appear. We also have another model, let's call it RelatedModel, which should have a one-to-one relation to BaseModel: class RelatedModel(models.Model): the_thing = models.OneToOneField(BaseModel, null=True, blank=True) Is it possible to do define such a relation if BaseModel.Meta.abstract == True? Or

2021-06-15 16:44:07    分类:问答    django   model   abstract

Newbie Django Model Error

With Python 2.7.x + Django 1.9: I create a new super-simple Django skeleton project with django-admin startproject simple As a sanity check, I create a views.py file with a simple view that outputs a "hello world" type test message and a url route to that view. I can run this with python manage.py runserver and it works fine. I create a models.py file with a single super simple Django ORM model class. FYI, my goal is to use existing tables and schema, so I don't want the ORM to generate new tables. class SuperSimpleModel(models.Model): some_value = models.CharField(blank=True, null=True) class

2021-06-15 16:40:56    分类:问答    python   django   django-models   django-views

Django Compressor Blank Css Output File

When django compresses css it saves the output to a file in /static/CACHE/css/[filename].css, however no matter what I try, the css file keeps coming out blank! In my template... {% compress css %} <link rel='stylesheet' type='text/less' href='{{ STATIC_URL }}css/deals_for_you.less'/> {% endcompress %} I installed django_compressor, django_appconf, and versiontools successfully I installed lessc successfully (testecd) STATICFILES_FINDERS are set COMPRESS_OFFLINE = True COMPRESS_ENABLED = True COMPRESS_OFFLINE_CONTEXT = { 'STATIC_URL': STATIC_URL, } COMPRESS_PRECOMPILERS = ( ('text/less',

2021-06-15 16:34:49    分类:问答    python   css   django   compression

Retrieving “businesses” with Google Maps API?

This is an example of a Business on Google Maps It has elements attached such as: Reviews from various sites (qype, viewlondon, etc...) Details provided by various sites Photos and other content I don't know how to go on about retrieving such Business and associate any items generated on my website. What I have implemented up to date is a system using geocoding (geopy) which once given an address, it gives back Latitude and Longitude, but such system does not help me with this dilemma.

2021-06-15 16:27:27    分类:问答    django   google-maps   geocoding   google-api

Django Backend-neutral DictCursor

Is there any way to get a backend-neutral dictionary cursor in Django? This would be a cursor that is a dict rather than a tuple. I am forced to use Oracle for the school project I'm working on. in Python's MySQLDb module it's called a DictCursor. With WoLpH's inspiring suggestion I know I am very close.. def dict_cursor(cursor): for row in cursor: yield dict(zip(cursor.description, row)) Iterating and printing each row cursor used to result in: (482072, 602592, 1) (656680, 820855, 2) (574968, 718712, 4) (557532, 696918, 3)) But with dict_cursor I get: {('NET_SPENT', <type 'cx_Oracle.NUMBER'>

2021-06-15 16:11:12    分类:问答    python   database   django   cursor   dictionary

django messages not showing

I'm trying to use django messages framework to display a message when a user signs out of my application. I'm new to django and the documentation isn't very clear to me. Why is my message not showing up? https://docs.djangoproject.com/en/dev/ref/contrib/messages/#adding-a-message VIEW.PY from django.contrib import messages def signout(request): logout(request) messages.add_message(request, messages.INFO, 'Signout Successful.') return HttpResponseRedirect(reverse(index)) def index(request): lf = LoginForm() if request.method == "POST": username = request.POST['username'] password = request.POST

2021-06-15 16:06:08    分类:问答    python   django   templates   view   messages