Login required always render to home page

when I am using login_required it does not rendering to appropriate url it always render to home page only login view def login_view(request): print(request.user.is_authenticated()) w="Welcome" title = "Login" form = UserLoginForm(request.POST or ...
more »

2017-02-14 16:02 (1) Answers

Nested router not working

I'm new to Django and am struggling to get nested routers working. Basically, I'm trying to model the endpoint /api/v1/organizers/1/events/1, where I have Event and Organizer models as follows: class Event(models.Model): class Meta: db_t...
more »

2017-02-14 10:02 (1) Answers

Pytest-django: set user permissions

I work on a library for Django using pytest 3.0.6 and pytest-django 3.1.2. I have this very simple test failing, and I don't understand what happen: # test_mytest.py import pytest from django.contrib.auth.models import Permission from django.contrib...
more »

2017-02-14 08:02 (2) Answers

Can't log in to Django admin locally or in prod

I'm having two problems with my new Django admin, but I'm not sure if they're related so I don't want to split them into two questions just yet. The site is live and working--I went to the admin for the first time and got a csrf error. So I went ba...
more »

2017-02-14 04:02 (1) Answers

Why django urls end with a slash?

Django official documentation and other tutorials on the web always use a trailing slash at the end of url. ex: url(r'^accounts/login/', views.login) # login view in turn calls login.html # instead of url(r'^accounts/login', view.login) Since a...
more »

2017-02-13 20:02 (3) Answers

django jeft join query

I have following models: class TestCaseStatus(models.Model): name = models.CharField(default='n/a', max_length=50) def __str__(self): return self.name class TestCase(models.Model): id = models.CharField(unique=True, max_length=...
more »

2017-02-12 04:02 (1) Answers

Django: Avoid showing error details in production

I am trying to make sure that my site is properly protected from showing the details of the error in production. I've been struggling with this for a while, as at beginning I understood that in order to avoid Django from showing the error (module, l...
more »

2017-02-11 19:02 (1) Answers

Django form submit does not work

I have an EventForm form that i want to populate. I use event_form.attributes so I can customize the CSS. But nothing happens when I click submit - the action url is not called or anything. EventForm: class EventForm(forms.ModelForm): name = fo...
more »

2017-02-11 18:02 (1) Answers

TypeError only with celery

I am using Django. So there is an option CELERY_ALWAYS_EAGER. When I switch off celery workers with CELERY_ALWAYS_EAGER = True, everything is ok. When CELERY_ALWAYS_EAGER = False I get an error: TypeError: unsupported operand type(s) for -: 'unicod...
more »

2017-02-11 17:02 (1) Answers

Django failed to load templates in eclipse

I just tried to test app I made in localhost and it keep gives me a message that templates does not exit even though I made it in eclipse. When I checked it was trying to load templates where those are not exist. Template-loader postmortem Django ...
more »

2017-02-11 06:02 (0) Answers

Composite Foreign Key in Django

I need a Composite Foreign Key in Django, which isn't supported. I could add it manually to the DB, or through migrations but then it won't be reflected in the model definition (sadpanda). The backend DB is postgres. Here's my models: class Trial(m...
more »

2017-02-10 19:02 (0) Answers

Search Engine Optimization with hash in url

I have a site let's say xyz.com. It has urls like xyz.com#abc. Now the front end (which is in angular js) is creating # in the url. The calls first go to nginx and from there they are redirected to django server. Now SEO does not work properly when t...
more »

2017-02-10 18:02 (1) Answers

Django QuerySet select related objects

I have searched around but have not found a situation like mine. Assuming the use of Django's User Profile method to extend the default user features, how would a multi-object queryset get mapped a queryset of the related object. For example (in the...
more »

2017-02-10 04:02 (1) Answers

Django: adding two serializers together?

How is it possible to add a serializer within another serializer? Here's what I mean: I have a UserProfile model as such: class UserProfile(models.Model): user = models.OneToOneField(User) photo = models.URLField(max_length=128) I have p...
more »

2017-02-10 00:02 (1) Answers

Using Django to make a stateful connection

I'm trying to use Django in the following way. I have a command line utility that runs on the backend, lets call it foo. I want foo to run when at least one person is on a django page foo.com/kungfoo. I also need to kill the script, when they le...
more »

2017-02-10 00:02 (1) Answers

Form action isn't triggering at all

Basically I am currently trying to work around the fact that you have to do a HttpResponseRedirect after form submission to avoid repeat submissions on page refresh. So I want my submit button for my form to trigger another view, not submit the cur...
more »

2017-02-09 15:02 (1) Answers