Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
how to get the list and detail views on the same one page website template
im trying to acheive this. 1. one page website with a list and detail view on the same template. when the website loads, i have the thumbnails with all the list of items, i show that using a for loop and listview. under that i have the same thing(items from the model) but in a form of carousel.( i can see all the items from the model in the slider with complete details) these work fine. buti want a detailed view in the same carousel slider. for eg: the user can see the list of items (thumbnail) and when clicked on a item , that particular item should be active in the slider, 1. i cant get the list and detail view to work on the same template. 2.i cant get the detailed view to work in the same carousel slider. MODELS.PY class Cheese(models.Model): TYPES_CHOICES=( ('COW', 'COW'), ('GOAT', 'GOAT'), ('SHEEP', 'SHEEP'), ('BUFFALO', 'BUFFALO'), ('COW, GOAT & SHEEP', 'COW, GOAT & SHEEP'), ('COW & SHEEP', 'COW & SHEEP') ) COUNTRY_CHOICES=( ('USA', 'USA'), ('UK','UK'), ('ITALY', 'ITALY'), ('FRANCE', 'FRANCE'), ('NETHERLANDS', 'NETHERLANDS') ) origin = models.CharField(max_length=100) title = models.CharField(max_length=100) types = models.CharField(max_length=100, choices=TYPES_CHOICES) about = models.TextField() serve = models.CharField(max_length=1000) image = models.ImageField( null=True, blank=True, … -
Django QuerySet Filter by week_day returning nothing
I am currently trying to filter my QuerySet results by the day of the week in Django 2.0. I can't for the life of me get the django week_day filter datetime__week_day to return any results. Model class Session(models.Model): def __str__(self): return str.join(', ', (str(self.game.name), str(self.datetime_created), str(self.start))) game = models.ForeignKey( 'Game', on_delete=models.PROTECT, blank=False, null=False, ) datetime_created = models.DateTimeField(auto_now_add=True,) start = models.DateTimeField(blank=True, null=True,) end_time = models.TimeField(blank=True, null=True,) competitive = models.BooleanField(default=False,) Filtering filtered_sessions = Session.objects.filter( start__week_day=2, ).exclude(start__isnull=True) I currently have an entry in the sessions table (MySQL backend) which contains the datetime 2018-04-30 23:51:42.000000, so I would expect this QuerySet to contain that 'Session' as it occurs on a Monday. Referring back to the documentation, The week goes from Sunday(1) to Saturday(7). My question is this: Why is what I am trying is not returning any results? Please let me know if I've left out something that would help answer my query. Thanks! -
Updating through put getting exception : Incorrect type. Expected pk value, received dict
I have the following two models class modelJob(models.Model): category = models.ForeignKey(modelJobCategory,on_delete=models.CASCADE,null=True,default=None,blank=True) description = models.CharField(max_length=200, unique=False) and this model class modelJobCategory(models.Model): name = models.CharField(max_length=200, unique=True) other = models.CharField(max_length=200, unique=False , blank=True , null=True) These are my two serializers class Serializer_Update_Job_Serializer(ModelSerializer): class Meta: model = modelJob category = Serializer_Create_List_JobCategory fields = [ 'category', 'description', ] class Serializer_Create_List_JobCategory(ModelSerializer): class Meta: model = modelJobCategory fields = [ 'name', 'other', ] Now I am attempting to update through PUT at the url with a lookup field pk however I am getting the exception { "category": [ "Incorrect type. Expected pk value, received dict." ] } This is what my view looks like class UpdateJob_RetrieveUpdateAPIView(RetrieveUpdateAPIView): queryset = modelJob.objects.all() serializer_class = Serializer_Update_Job_Serializer lookup_field = 'id' def put(self, request, *args, **kwargs): object = self.queryset return self.update(request, *args, **kwargs) Any idea why I am getting this error ? -
Django Rest Framework many to many crate and update
models.py: class Book(models.Model): name = models.CharField(max_length=100) description = models.TextField(max_length=500) image = models.ImageField(height_field="height_field", width_field="width_field") height_field = models.IntegerField(default=255) width_field = models.IntegerField(default=255) price = models.FloatField() edition = models.CharField(max_length=100) no_of_page = models.IntegerField() country = models.CharField(max_length=50) publication = models.ForeignKey(Publication, on_delete=models.CASCADE) authors = models.ManyToManyField(Author, through='AuthorBook') ratings = GenericRelation(Rating, related_query_name='books') class AuthorBook(models.Model): author = models.ForeignKey(Author, on_delete=models.CASCADE) book = models.ForeignKey(Book, on_delete=models.CASCADE) class Author(models.Model): name = models.CharField(max_length=100) biography = models.TextField(max_length=500) image = models.ImageField(height_field="height_field", width_field="width_field") height_field = models.IntegerField(default=255) width_field = models.IntegerField(default=255) serializers.py class AuthorListSerializer(ModelSerializer): url = author_detail_url class Meta: model = Author fields = [ 'url', 'id', 'name', ] class BookCreateUpdateSerializer(ModelSerializer): authors = AuthorListSerializer(many=True, read_only=True) def create(self, validated_data): #code def update(self, instance, validated_data): #code class Meta: model = Book fields = [ 'name', 'description', 'price', 'edition', 'no_of_page', 'country', 'publication', 'authors', ] views.py class BookCreateAPIView(CreateAPIView): queryset = Book.objects.all() serializer_class = BookCreateUpdateSerializer I am working for implementing Django Rest framework. I have two models Book and Author. But django create api view don't show authors field drop down. I checked many solution DRF for many to many field. Please help me to show authors field and write create() and update function. If you see DRF api page, it will be clear. -
Django simple categories list
sorry for asking such simple question, but I got stuck on (as i think) trivial problem. I have a simple gallery model in Django and want to get a photos category list. My model looks like that: class Photo(models.Model): title = models.CharField(max_length=150) image = models.ImageField() description = models.TextField() category = models.IntegerField(choices=CATEGORIES) published = models.DateTimeField(default=timezone.now) def __str__(self): return self.title And the choices.py file looks like this: CATEGORIES = ( (1, ('Mountains')), (2, ('Animals')), (3, ('Macro')), (4, ('People')) ) What I'm looking for is getting list like that: Mountains | Animals | Macro | People in my templates. -
(Django-Celery Error) ImportError: No module named myproject
I am using Django-Celery for the first time. When I try to run the following command : celery -A MyProject worker -l info I get this error message: ImportError: No module named MyProject MyProject/MyProject/init.py : from __future__ import absolute_import, unicode_literals from .celery import app as celery_app __all__ = ['celery_app'] MyProject/MyProject/celery.py: from __future__ import absolute_import import os import sys from celery import Celery from django.conf import settings os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MyProject.settings') app = Celery('MyProject') app.config_from_object('django.conf:settings', namespace='CELERY') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'MyProject.settings') sys.path.insert(0,os.path.abspath(os.path.join(os.path.dirname(__file__),'../MyProject'))) app.autodiscover_tasks() MyProject/MyProject/settings.py; I have included the line below : CELERY_BROKER_URL = 'amqp://localhost' My Django project structure looks like this: Myproject Myproject init.py celery.py settings.py urls.py wsgi.py Myapp migrations/ templates/ init.py admin.py apps.py forms.py models.py tasks.py tests.py urls.py views.py db.sqlite3 manage.py -
INTERNAL_IPS and ALLOWED_HOSTS in django settings
What is INTERNAL_IPS and ALLOWED_HOSTS in django settings.Why we are using it,what happen if we not use it. -
Django: JWT: will it allow to keep user logged in even i open the domain in new tab
I am creating a webapp and mobile app using DJango. I am using DRF to generate rest api. I will be using JWT token authentication for users to login in. I will passing the token in Authorization header through javascript and not by cookie Assuming some one logs in to my domain (eg: sample.com) in a browser, now if i open sample.com in new tab will I have to again login or browser will remember that i have already logged in. -
Django always returning invalid form during signup
I am trying to implement email authentication during sign up. But always the compiler returning the invalid form. Can anyone suggest what may be the reason behind this? I am using SALEOR package for this project. Below I have posted model, forms and views code models.py class User(PermissionsMixin, AbstractBaseUser): email = models.EmailField(unique=True) addresses = models.ManyToManyField(Address, blank=True) is_staff = models.BooleanField(default=False) is_active = models.BooleanField(default=True) date_joined = models.DateTimeField(default=timezone.now, editable=False) default_shipping_address = models.ForeignKey( Address, related_name='+', null=True, blank=True, on_delete=models.SET_NULL) default_billing_address = models.ForeignKey( Address, related_name='+', null=True, blank=True, on_delete=models.SET_NULL) USERNAME_FIELD = 'email' objects = UserManager() forms.py class SignupForm(forms.ModelForm): password = forms.CharField( widget=forms.PasswordInput) email = forms.EmailField( error_messages={ 'unique': pgettext_lazy( 'Registration error', 'This email has already been registered.')}) class Meta: model = User fields = ('email',) labels = { 'email': pgettext_lazy( 'Email', 'Email'), 'password': pgettext_lazy( 'Password', 'Password')} def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if self._meta.model.USERNAME_FIELD in self.fields: self.fields[self._meta.model.USERNAME_FIELD].widget.attrs.update( {'autofocus': ''}) def save(self, request=None, commit=True): user = super().save(commit=False) password = self.cleaned_data['password'] user.set_password(password) if commit: user.save() return user views.py the else part of if form.is_valid getting executed every time def signup(request): if request.method == 'POST': form = SignupForm(request.POST or None) print('POST Method') if form.is_valid(): print('Valid Form') user = form.save(commit=False) user.is_active = False user.save() current_site = get_current_site(request) mail_subject = "Activate Your Account" … -
How to check initial data when save model in ModelAdmin?
I use save_model() method in ModelAdmin. I want to do sth when specific field changed (i.e. staus). So I want to know initial data before save admin so I could check it in save_model. I knew that there's __init__ and __save__ method in Model itself, but I want to activate code only in ModelAdmin. Here's sample code below def save_model(self, request, obj, form, change): if obj.status != xxx (intial data?) and obj.status == 7: # do sth super(StraightOrderAdmin, self).save_model(request, obj, form, change) Summary Can I know initial data from obj after save in admin? Is there any way to do sth when only saving in admin site? Thanks in advance. -
Fetching all images corresponding to one id in django
I have one table with post data and one table with post_image(s) and connected through post_id. Now I want a query set which will help me fetch all the images from table 2 with respect to post id.I am using post_image = Post_image.objects.filter(post=post) but it's giving empty query set and post_image = Post_image.objects.filter(post=post.id) is giving me 'QuerySet' object has no attribute 'id' error. Views.py: def create(request): # dogs.save() user = request.user #print (user) if request.method=="POST": post = Post(title=request.POST['title'], description=request.POST['description'], created_by_user=user,) post.save() image=request.FILES.getlist('image') print image import pdb;pdb.set_trace() for x in image: post_image = Post_image( image=x, post=post ) post_image.save() #import pdb;pdb.set_trace() return redirect("/") def error(request): return render(request, '404.html') def view(request): if request.user.is_authenticated(): #or request.session.get_expiry_age()> 10): request.session.set_expiry(600) user = request.user #dogs=Post.objects.all() #For seeing all entries post= Post.objects.filter(created_by_user = user).order_by('-created_at')#[:4] #For seeing user specific entries post_image = Post_image.objects.filter(post=post.id) context={'post': post , 'post_image': post_image} return render(request, 'view.html', context) else: messages.info(request, 'Session Expired') return redirect("/login") models.py: # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.utils.encoding import python_2_unicode_compatible from django.db import models from django.conf import settings from django.contrib.auth.models import User # Create your models here. class Post(models.Model): # user = models.ForeignKey(User, unique=True) title=models.CharField(max_length=100) description=models.CharField(max_length=4500) created_at=models.DateTimeField(auto_now_add = True) updated_at=models.DateTimeField(auto_now= True) # user = models.OneToOneField(User, null=True) created_by_user … -
Different class in HTML depending of screen size
I'm newbie in bootstrap and I don't know how to do the following: I'm working with Django and in my HTML template I have this: <div class="tabs tabs-vertical tabs-left"> <ul class="nav nav-tabs"> This works fine with large screens, but it looks ugly when I access into the page with my phone, so I need that my template look like this if the screen is xs: <div class="tabs"> <ul class="nav nav-tabs nav-justified flex-column flex-md-row"> Can this be done with bootstrap? It's necessary to clone the entire div content and hide depending of screen? Thank you. -
Coinbase Python Seems to Cache OAuth User
I'm adding Coinbase OAuth to my Django application and something seems to be caching the first user that was authenticated. When the following code is run by the Django application it always returns the same user and accounts. I have verified that it is passing the correct user for the session but the current_client_user does not match. client = OAuthClient(user.access_token, user.refresh_token) current_client_user = client.get_current_user() accounts = client.get_accounts() Running the same code in the Django shell returns the correct user info and accounts. What would explain this? I don't see any reference to caching in the Coinbase Python library documentation. -
how to set setting file when file download by django+nginx+uwsgi
I wrote the file download code using the django + nginx + uwsgi following is my code def download_latest_db(request): latest_db = DB.objects.all().first() chunk_size = 8192 if latest_db is not None: response = FileResponse(FileWrapper(open(latest_db.locate, 'rb'), chunk_size)) response['Content-Length'] = os.path.getsize(latest_db .locate) response['Content-Disposition'] = 'attachment; filename="%s.db"'% latest_db.version return response return Response(status=404) but file download almost failed when i try five times and it doesn't occur in runserver mode i guess it's problem with nginx setting. please help me -
why can't I upload zip file in dango form
I used django form.forms to upload file. The problem is I can upload files of all format except zip. When I click the submit button, the server can't even receive the request. And, when I upload zip file in local host, it can work. This the views.py. if request.method == "POST": pass else: form = FeatureScenarioForm() return render_to_response('downloadtest/formtest.html') This is the form form.py from django import forms class FeatureScenarioForm(forms.Form): feature_file = forms.FileField() This is the html file. <form action="upload" method="post" enctype="multipart/form-data"> {% csrf_token %} <div class="mb-3"> <label class="h4">Feature Options</label><br> {{ form.feature_file }}<br> </div> <input type="submit" value="Submit" class="btn btn-primary btn-sm btn-block" style="width:200px;height:40px"> </form> -
Django Rest Framework, how to filter for the selected fields?
I'm using django rest framework and writing raw SQL queries to filter data. I want to select only one field from the serializer fields based on the user's selection. For example, if user wants to see only product1_revenue the drf only serialize for that field. But somehow drf ignore the selection and provides data for all the fields. How can I select only one field? views.py class FilteredFinancialData(generics.ListAPIView): serializer_class = FinancialDataSerializer def get_queryset(self, *args, **kwargs): queryset_filtered = FinancialData.objects.raw('SELECT id, product1_revenue' ' from myapp_financialdata' ' WHERE financial_year_id = 2017' 'and financial_month_id between 1 and 3') return queryset_filtered serializers.py class FinancialDataSerializer(serializers.ModelSerializer): class Meta: model = FinancialData fields = ( 'financial_year', 'financial_month', 'product1_revenue', 'product2_revenue', 'product3_revenue', 'product4_revenue', 'product5_revenue',) -
In Django, how to delegate certain fields to corresponding fields of a foreign key if they are null/blank?
Consider these two models, CheckInType and CheckIn, with a one-to-many relationship (in models.py): from django.db import models class CheckInType(models.Model): title = models.CharField(blank=True, max_length=255) description = models.TextField(blank=True) class CheckIn(models.Model): checkin_type = models.ForeignKey(CheckInType, null=True, on_delete=models.CASCADE) title = models.CharField(blank=True, max_length=255) description = models.TextField(blank=True) def __getattribute__(self, attr): if attr in ['title', 'description'] and not CheckIn.__getattribute__(self, attr) and CheckIn.__getattribute__(self, 'checkin_type'): return CheckInType.__getattribute__(self.checkin_type, attr) return CheckIn.__getattribute__(self, attr) I would like to make it such that when, for an instance checkin of CheckIn, you try to access the attribute checkin.title and it is falsey (None or an empty string), but if the checkin does have a checkin_type, it will return checkin.checkin_type.title (and similarly for the description field). I've tried to implement this by overriding the __getattribute__() method for the CheckIn model as shown above. According to the Python docs, This method should return the (computed) attribute value or raise an AttributeError exception. In order to avoid infinite recursion in this method, its implementation should always call the base class method with the same name to access any attributes it needs, for example, object.__getattribute__(self, name). I've tried to take this into account by replacing object with a class and self with an instance. However, if I try to … -
querysets in models with manytomany fields (Django)
My question is associated with making querysets on models that are interconnected across many to many fields. context - an app that a student enters and has to rate his or her teachers. the questions the app shows the student have the following logic: each student must rate some teachers. Each teacher has different categories of questions associated with them ("intelligence", "respect", "empathy",etc.) and each of these categories has some questions associated with it. The models are: class Items(models.Model): item = models.TextField() def __str__(self): return self.item class Categories(models.Model): category = models.CharField(max_length=50,null=True) items_associated = models.ManyToManyField(Items) def __str__(self): return self.category class Professors(models.Model): professor = models.CharField(max_length=50,null=True) categories_assigned = models.ManyToManyField(Categories) def __str__(self): return self.professor class Students(models.Model): student_logged = models.CharField(max_length=50,null=True) professors_to_evaluate = models.ManyToManyField(Professors) def __str__(self): return self.student_logged when a student enters the web has some associated teachers (model Students) these teachers in turn have some categories assigned (model Professors), these categories in turn have some questions associated (model Categories). I want to store in a dictionary these questions that are in the model Items. How can I do it? I've tried to filter and __in but I can't get it. Many thanks and thank you for the wisdom -
How would I turn this query joining multiple tables together with multiple columns into a Django queryset?
I have this query that joins multiple tables together: select p.player_id , d.player_data_1 , l.year , l.league , s.stat_1 , l.stat_1_league_average from stats s inner join players p on p.player_id = s.player_id left join player_data d on d.other_player_id = p.other_player_id left join league_averages as l on l.year = s.year and l.league = s.year where p.player_id = 123 My models look like this: class Stats(models.Model): player_id = models.ForeignKey(Player) stat_1 = models.IntegerField() year = models.IntegerField() league = models.IntegerField() class Player(models.Model): player_id = models.IntegerField(primary_key=True) other_player_id = models.ForeignKey(PlayerData) class PlayerData(models.Model): other_player_id = models.IntegerField(primary_key=True) player_data_1 = models.TextField() class LeagueAverages(models.Model): year = models.IntegerField() league = models.IntegerField() stat_1_league_average = models.DecimalField() I can do something like this: Stats.objects.filter(player_id=123).select_related('player').select_related('player_data') to do the first two joins. However, how would I do the third join considering that year and league aren't foreign keys in any of the tables? -
djangorestframework 'PUT'/'PATCH' method not working
I am fairly new to DRF and FK and have been trying to do a 'PUT'/'PATCH' for an app but unsuccessful so far. The rest of the CRUD operations work fine. There is a FK element that I think is causing problems for this particular operation. How do I get the update - 'PUT'/'PATCH' function going here? Your help will be greatly appreciated - Many thx in advance :) Here are the relevant snippets - models.py from django.db import models # Create your models here. class House(models.Model): house = models.CharField(max_length=50) parent_house = models.ForeignKey('self', related_name='base_house', blank=True, null=True, on_delete=models.CASCADE) attributes = models.ManyToManyField('HouseAttributes', through='HouseAttributesMapping') class Meta: db_table = 'sku' def __str__(self): return "%s" % self.sku class HouseAttributes(models.Model): house_attribute = models.CharField(max_length=50, unique=True) class Meta: db_table = 'house_attributes' def __str__(self): return "%s" % self.house_attribute class HouseAttributesMapping(models.Model): house = models.ForeignKey(House, on_delete=models.CASCADE) house_attribute = models.ForeignKey(HouseAttributes, on_delete=models.CASCADE) value = models.CharField(max_length=50) class Meta: db_table = 'house_attributes_mapping' views.py from .models import House, HouseAttributes, HouseAttributesMapping from serializers.skuSerializer import HouseListSerializer, HouseDetailSerializer from rest_framework import generics, mixins from rest_framework import viewsets # Create your views here. class HouseListApi(mixins.ListModelMixin, mixins.CreateModelMixin, generics.GenericAPIView): queryset = House.objects.all() serializer_class = HouseListSerializer def get(self, request, *args, **kwargs): return self.list(request, *args, **kwargs) def post(self, request, *args, **kwargs): return self.create(request, *args, … -
502 error nothing is listening on port 8000 nginx
I have ran into a problem when trying to deploy my web server, where I'm getting a 502 bad gateway error. When looking in the nginx error logs, I get this: failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xx, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "example.com" I then ran sudo netstat -tnlp | grep :8000 to see if anything is listening on port 8000, but got no output, meaning that indeed nothing is listening on port 8000. Also, here are my nginx configurations in sites-enabled: upstream app_server { server unix:/home/daniel/myproject/myproject.sock fail_timeout=0; } server { listen 80; server_name 138.197.152.54; client_max_body_size 50M; location = /favicon.ico { access_log off; log_not_found off; } location /static/ { root /home/daniel/myproject; } location / { include proxy_params; proxy_pass http://127.0.0.1:8000/; proxy_redirect off; # proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 30; proxy_read_timeout 30; } I'm wondering if the port the server is listening on is false, since the proxy pass has 127.0.0.1:8000, and on top, the server is apparently listening on port 80. Is something wrong with my configurations? I'm quite new to working with nginx, gunicorn, and would very much appreciate any help on this issue. -
Django--Making query use part of the matching name
Currently I am working on Django. I defined a 'Search' function in views.py: def search(request): q = request.GET.get("q") if q: ReactResul = Reactionsmeta.objects.filter(id__contains=q) MetaResul = Metabolites.objects.filter(id__contains=q) GeneResul = Genes.objects.filter(id__contains=q) else: # you may want to return Customer.objects.none() instead ReactResul= Reactionsmeta.objects.all() GeneResul = Genes.objects.all() MetaResul = Metabolites.objects.all() context = dict(result_1=MetaResul, q=q, result_2=ReactResul, result_3 = GeneResul) return render(request, "Recon/search.html", context) And now I want to make it more powerful. If I want to search '10FTH86RSK' but I cannot remember the whole name, I can just use part of the string to make query. For example, if I type '10FTK', '10FTH86RSK' should be returned as result. In that case, '10FTK', '10F6TK' or '10FTK4' should also be returned as results. So how could I achieve this function? -
django creates new model instead of updating
I'm currently working on a news website using django and I'm having an issue in updating categories. I have created a view that takes the old category name and the new category using a form. This is my code def update_category(request): if request.method=='POST': old_name=request.POST.get('old_name').strip() # get old name new_name=request.POST.get('new_name').strip() # get new name categorie=Category.objects.get(title=old_name) # get category by title (pk) categorie.title=new_name # update the title categorie.save() # save to the database return HttpResponseRedirect('/admin/Category_Management) For example, if I try to change category "Technology" to "Computer Science", django creates a new category called "Computer Science" without updating "Technology" This is my category model class Category(models.Model): class Meta: verbose_name='Catégorie' verbose_name_plural='Catégories' title=models.CharField(primary_key=True,max_length=50,null=False,blank=False,verbose_name='Titre') def __str__(self): return self.title.title() -
Django: How to get the click information of a user?
I'm building a website that will show for the user (already logged in) a question. I will give the user the option (buttons) to vote YES and NO, I would like to know how to get the information when the user click YES or NO, and store this value in the database. I'll need this information later. It will be something around 30 questions, I don't have the number yet. I would like some clarification on how to do that. -
Caddy throws duplicate site address with production.yml django cookie cutter
I'm using Django cookie cutter docker project trying to host on digital ocean. I tried to bring it up, It worked fine once, but later I made some changes to django code and had to restart it. So I stopped all the thins and fired up command again from themn onwards I'm getting this error My Caddy env file: Caddy ------------------------------------------------------------------------------ DOMAIN_NAME=balajidigitals.in My production Caddyfile : www.{$DOMAIN_NAME} { redir https://balajidigitals.in } {$DOMAIN_NAME} { proxy / django:5000 { header_upstream Host {host} header_upstream X-Real-IP {remote} header_upstream X-Forwarded-Proto {scheme} } log stdout errors stdout gzip } now when I run docker-compose -f production.yml up Caddy throws the following error caddy_1 | 2018/04/25 22:34:15 duplicate site address: balajidigitals.in balaji_digitals_caddy_1 exited with code 1 what did I do wrong. and one more doubt If I make changes to my django code Can I restart only django service instead of all the things. my questions may be stupid as I am very new to docker