Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django REST framework Ajax call only works on the first call
The tutorial I am following has this code which works when the page is first loaded, and then it does not. I have read all other questions on "ajax call works the first time only", but could not find a relevant cause. Given that the code works when the page loads, I think there is a binding problem in the jQuery portion that prevents the button to act once it is changed on the first call, but I cannot pinpoint what that is. I also tried visiting the url end-point (REST framework end-point) and every time I refresh the page, the count does update correctly. So, the problem must be somewhere in the front-end since it can clearly find the URL and update the count once but fails to call ajax on subsequent clicks. <li> <a class="like-btn" data-href="{{ obj.get_api_like_url }}" data-likes='{{obj.likes.count}}' href="{{ obj.get_api_like_url }}"> {{obj.likes.count }} | {% for person in obj.likes.all %} {{ person.userprofile.first_name }} {% endfor %}<i class="fab fa-gratipay"></i> </a> </li> In my jQuery code: $(function(){ $(".like-btn").click(function(e) { e.preventDefault(); var this_ = $(this); var likeUrl = this_.attr("data-href"); console.log("likeUrl: ", likeUrl); var likeCount = parseInt(this_.attr("data-likes")) | 0 ; var addLike = likeCount; var removeLike = likeCount; if (likeUrl) { … -
Django rest framework handle duplicates
I am building an app where I use django as backend and react native as front end. Right now I am building a login component which provides Facebook and Google login and the data returned from their API's is stored in my local database trough DRF. The problem is that when a user signs out and log in again DRF creates another record with exactly the same info. Now, the question is should I handle this in the backend (and if yes how) or in the front end (here I know how, but I think its not a good idea) Here are my django model, view and serializer: class RegisteredUsers(models.Model): userId = models.CharField(max_length=256) user_name = models.CharField(max_length=256) user_mail = models.CharField(max_length=256) photo = models.CharField(max_length=256) def __str__(self): return self.user_name class RegisteredUsersViewSet(viewsets.ModelViewSet): queryset = RegisteredUsers.objects.all() serializer_class = RegisteredUsersSerializer def get_queryset(self): mail = self.request.query_params.get('user_mail', None) if mail: qs = RegisteredUsers.objects.all().filter(user_mail=mail) else: qs = super().get_queryset() return qs class RegisteredUsersSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = RegisteredUsers fields = ('userId', 'user_name', 'user_mail', 'photo') lookup_field='user_mail' extra_kwargs = { 'url': {'lookup_field': 'user_mail'} } how can I validate that this account already exists and just log in the user? -
How to enforce using a char(n) datatype instead of nvarchar in Django queries with django-mssql-backend
I am using, python 3.7, django 2.2 and django-mssql-backend with a legacy Microsoft SQL Server 2012 database. I have generated a model using inspectdb. The model has a field called “ord_no” which is a CHAR(8) datatype in the database. Django correctly creates it as a CharField(max_length=8). Note – There is an index for this table on the ord_no column. Here is the simplified table definition: CREATE TABLE [dbo].[imordbld_sql]( [ord_no] [char](8) NOT NULL, [item_no] [char](30) NOT NULL, [qty] [decimal](13, 4) NULL, [qty_per] [decimal](15, 6) NULL, [ID] [numeric](9, 0) IDENTITY(1,1) NOT NULL ) ON [PRIMARY] GO Here is my models.py with a simplified version of the model in question with fields auto-generated through inspectdb I've also created a custom model manager that converts the ord_no parameter into a CHAR(8) field for demonstration purposes. models.py from django.db import models class OrderBuildManager(models.Manager): """ Django automatically use nvarchar(16) instead of char(8) when using the ORM to filter by work order. This method casts the ord_no parameter to a char(8) so SQL can use an index on the ord_no column more efficiently (index seek vs index scan) """ def get_order(self, ord_no): qs = super(OrderBuildManager, self).get_queryset().extra( where=('ord_no = CAST(%s as CHAR(8))',), params=(ord_no,)) return qs class OrderBuild(models.Model): ord_no … -
'MultiValueDict' object has no attribute 'name'
I am using jQuery - Filer.js for file upload, when I upload any file it returns Error like "'MultiValueDict' object has no attribute 'name'" settings.py MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') fileupload.html <div class="card-block"> {% csrf_token %} <input type="file" name="files[]" id="filer_input1"> </div> views.py from django.shortcuts import render,redirect from django.http import HttpResponse, HttpResponseRedirect from django.core.files.storage import FileSystemStorage def StorePartyMappingIndex(request): return render(request,'storepartymapping.html') def StorePartyMappingfileupload(request): if (request.method == 'POST'): file = request.FILES fs = FileSystemStorage() fs.save(file.name,file) # Error line return HttpResponseRedirect('/mapping/fileupload') else: return render(request,'fileupload.html') jquery: $(document).ready(function(){ 'use-strict'; $("#filer_input1").filer({ limit: 2, maxSize: 3, extensions: ['csv', 'xlsx', 'xls'], changeInput: '<div class="jFiler-input-dragDrop"><div class="jFiler-input-inner"><div class="jFiler-input-icon"><i class="icon-jfi-cloud-up-o"></i></div><div class="jFiler-input-text"><h3>Drag & Drop files here</h3> <span style="display:inline-block; margin: 15px 0">or</span></div><a class="jFiler-input-choose-btn btn btn-primary waves-effect waves-light">Browse Files</a></div></div>', showThumbs: true, theme: "dragdropbox", templates: { box: '<ul class="jFiler-items-list jFiler-items-grid"></ul>', item: '<li class="jFiler-item">\ <div class="jFiler-item-container">\ <div class="jFiler-item-inner">\ <div class="jFiler-item-thumb">\ <div class="jFiler-item-status"></div>\ <div class="jFiler-item-info">\ <span class="jFiler-item-title"><b title="{{fi-name}}">{{fi-name | limitTo: 25}}</b></span>\ <span class="jFiler-item-others">{{fi-size2}}</span>\ </div>\ {{fi-image}}\ </div>\ <div class="jFiler-item-assets jFiler-row">\ <ul class="list-inline pull-left">\ <li>{{fi-progressBar}}</li>\ </ul>\ <ul class="list-inline pull-right">\ <li><a class="icon-jfi-trash jFiler-item-trash-action"></a></li>\ </ul>\ </div>\ </div>\ </div>\ </li>', itemAppend: '<li class="jFiler-item">\ <div class="jFiler-item-container">\ <div class="jFiler-item-inner">\ <div class="jFiler-item-thumb">\ <div class="jFiler-item-status"></div>\ <div class="jFiler-item-info">\ <span class="jFiler-item-title"><b title="{{fi-name}}">{{fi-name | limitTo: 25}}</b></span>\ <span class="jFiler-item-others">{{fi-size2}}</span>\ </div>\ {{fi-image}}\ </div>\ <div class="jFiler-item-assets jFiler-row">\ <ul class="list-inline pull-left">\ <li><span … -
Django load html snippet template from js on input change
I have a Django template that loads a list of objects, for each of the object I load a template. Here are the HTMLs client-home.html: {% extends 'base.html' %} {% load static %} {% block content %} <div class="row"> <div class="col-md-2"> <div class="col"> <label for="city">City</label> <input name="city" type="text" class="form-control" id="city" value="{{ app_user.city }}"> </div> <div class="col mb-3"> <label for="category">Category</label> <select name="category" class="custom-select" id="category"> <option value="" selected>All</option> {% for category in categories %} <option value="{{ category.0 }}">{{ category.1 }}</option> {% endfor %} </select> </div> </div> <div class="col-md-10"> <ul class="list-group list-group-horizontal" id="offers-list"> {% for o in city_offers %} {% include "offer-snippet.html" with offer=o %} {% endfor %} </ul> </div> </div> {% endblock %} offer-snippet.html: <div class="row offer-box m-2"> <div class="col-5 p-0"> <img src="{{ o.owner.image.url }}" width="120" height="120" class="img-grey-bg"> </div> <div class="col-7"> {{ o.owner.name }} {{ o.city }}, {{ o.delivery_date }} <span class="badge badge-primary badge-pill">{{ o.current_subscribers }} / {{ o.min_subscribers }}</span> </div> </div> Here's the model.py: class BusinessOffer(models.Model): owner = models.ForeignKey(AppUser, related_name='offers', on_delete=models.CASCADE) created = models.DateTimeField(auto_now_add=True) city = models.CharField("City", max_length=50, ) delivery_date = models.DateField() min_subscribers = models.IntegerField() subscribers = models.ManyToManyField(AppUser, related_name='offers_subscribed_to') @property def current_subscribers(self): return len(self.subscribers.all()) As you can see, in the client-home.html there are 2 input fields. I would like to update … -
Images disappers while converting html to pdf with weasyprint
I am working on a django project, Sending data to html template which also contains a logo at the top, which is present in static folder and using template tagging to load it from static folder, when coverting that html template to pdf with weasyprint (using render_to_string) then i cant see the logo instead alternate text appears.I am deploying that project through docker so kindly can anyone solve my issue on both local machine and server. -
unable to solve : TypeError: expected str, bytes or os.PathLike object, not NoneType
(venv) C:\Users\user\Desktop\PJ\DiscussionForum\src>python manage.py makemigrations Traceback (most recent call last): File "manage.py", line 10, in execute_from_command_line(sys.argv) File "E:\PythonProjects\venv\lib\site-packages\django\core\management__init__.py", line 350, in execute_from_command_line utility.execute() File "E:\PythonProjects\venv\lib\site-packages\django\core\management__init__.py", line 342, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "E:\PythonProjects\venv\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv self.execute(*args, **cmd_options) File "E:\PythonProjects\venv\lib\site-packages\django\core\management\base.py", line 399, in execute output = self.handle(*args, **options) File "E:\PythonProjects\venv\lib\site-packages\django\core\management\commands\makemigrations.py", line 65, in handle loader = MigrationLoader(None, ignore_no_migrations=True) File "E:\PythonProjects\venv\lib\site-packages\django\db\migrations\loader.py", line 49, in init self.build_graph() File "E:\PythonProjects\venv\lib\site-packages\django\db\migrations\loader.py", line 170, in build_graph self.load_disk() File "E:\PythonProjects\venv\lib\site-packages\django\db\migrations\loader.py", line 95, in load_disk directory = os.path.dirname(module.file) File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\ntpath.py", line 215, in dirname return split(p)[0] File "C:\Users\user\AppData\Local\Programs\Python\Python38\lib\ntpath.py", line 177, in split p = os.fspath(p) TypeError: expected str, bytes or os.PathLike object, not NoneType -
Django-Heroku Deployment Procfile
I've created a basic Django app and I wanted to deploy it with Heroku. I have followed all the instructions given on Heroku but there was one error I made which was naming the file "procfile" instead of "Procfile". Now the website has been deployed but it only opens up to an application error. Upon checking the log, I have found the error code to be H14. I have since renamed the "procfile" to "Procfile" but the change doesnt seem to be integrated. How do I fix this? -
Cannot get model in Cron job Django
I'm working on Django Project in Which I have created an cron_job which does some work, but the problem I'm facing is I can't fetch my model in cron job function , I have never faced such issue before , Cron job function: def cron_job(): print("Function Executed") obj = Mymodel.objects.all() print("all objects ",obj) how I add cron job: python manage.py crontab add my cronjob executes but it only prints following in log file: Function Executed all objects #it should print all objects here and my models has data in it ,so it should work , I'm using workon virtualenv and python2.7 please help I don't know what to do, thanks in advance -
django: Issue with testing a view possibly caused by django-concurrency
I'm trying to create a test for an update view. I'm using django-concurrency and this specific view uses django-bootstrap-modal-forms. login = self.client.login(username='testuser', password='123456') #fails here response = self.client.post( reverse('edit_batch', kwargs={'pk': self.batch.id}), {'project': self.project.project_id, 'container': self.container.id, 'comment': 'Updated'}) self.assertEqual(response.status_code, 302) There exists a one-to-many between Container-Batch. So container is the parent of batch. The container itself also has several required related fields which need to be generated in setUp of the test. The issue I'm facing is that an exception is thrown from django concurrency when calling client.post: raise RecordModifiedError(_('Record has been modified'), target=target) concurrency.exceptions.RecordModifiedError: Record has been modified I've no idea why this is happening. Wasted hours now on this. Notably this works perfectly fine in the application itself. I can update correctly with no probelm. Only in test framework it fails. really puzzling. With debugging I can see that django.concurrency tells me that target has version 0 and saved one has version 1. Any idea what is causing this behavior? -
In django-cms Why preview button of page not able to load web page?
I have started to learn django-cms recently and got one project from one of my friends. I have created two pages in django-cms. When I click on preview(eye-icon) from pages, my second page preview does not show & instead showing below error. Page not found (404) Request Method: GET Request URL: http://localhost:8000/event-page/?edit&language=en Raised by: aldryn_newsblog.views.ArticleDetail No News / Blog Article found matching the query, tried languages: en You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page. I tried to find solution online but not able to find any. It will be great help if someone can suggest me solution. -
Some parts of Bootstrap 4 doesn't work with Django when served from static folder
I'm using Django with Bootstrap 4 without CDN. I'm using django_compressor and django-libsass for SASS and modify & extend with a separate sass file by importing the main bootstrap file. Most of the Bootstrap works but some don't. So far I discovered stretched-link and shadow don't work (I already enabled shadows in my sass). If I stop serving Bootstrap from static folder and use CDN instead, everything works fine. Does anyone know why this is happening? -
Converting a model to its base model
Consider this file : from django.db import models class Place(models.Model): name = models.CharField(max_length=50) address = models.CharField(max_length=80) class Restaurant(Place): serves_hot_dogs = models.BooleanField(default=False) serves_pizza = models.BooleanField(default=False) Now, let's say that I have a Restaurant, named restaurant. But this place is no longer a restaurant, so I want to transform it to a Place. For that, I do : p = Place.objects.get(pk=place_id) p.restaurant.delete() p.save() It works well, p is no longer a restaurant, but something strange happens : The primary key (ID) of p in the Place table change, like if the Place was deleted and then recreated. Why is this happening ? And how can I transform my restaurant to a place without changing the place ID ? -
How to access table which has its one to one relations?
Sorry, I don't know what should be the title for this question. But here is my question. In Django we User table comes as default. Now I have another table User_Info which has User id as (one-to-one/foreign key), I don't know what to take one-to-one or foreignkey. Now I want to access this User_Info table which has enrollment through the User table in HTML. (Is it possible?) example:- class User_info(models.Model): mobileNo = models.BigIntegerField(blank=True) User_id = models.OneToOneField(User, on_delete=models.CASCADE) we have User class as default and has primary key, username, email. <h1> Name {{ user.username }} </h1> <!-- we can have username stored in --> <h1> mobileNo {{ user.(i need help here, what to write)</h1> <!-- from user how to get mobile number--> If I am missing anything else please ask. Thank you:) I forget to mention that the user has already been logged in so I can have the user table access in HTML. -
Too many conditionals and validations in project
I have a Django project that takes JSON as input using drf APIs and performs variety of checks on that JSON and returns result accordingly. I am using JSON schema validation for verification of input. For further rules validations there are lot of checks for each input. Example of the scenario is for a JSON input, I need to check sequence of specific fields/objetcs, lowercase/uppercase keys and values, match input keys with certain set of pre-defined data and much more. My problem is that too many if else statements are making my code look ugly. I want to avoid that in a cleaner way. I am looking for suggestions to improve code quality. I have already divided most of it into different files. TIA -
How to submit a form without refreshing in django?
I know this question may be duplicates of many in stackoverflow. But those didn't help me out. I tried this but didn't succeed without refreshing. My models.py is: class Messages(models.Model): id = models.CharField(max_length=8, primary_key=True) messages = models.TextField() This is my html <form action="{% url 'messages' %}" method="post" id="new_message_form"> {% csrf_token %} <label for="">message</label><br> <textarea id="message" cols="30" rows="10"></textarea><br> <button type="submit">Submit</button> </form> This is my views.py: def messages(request): if request.method == "POST": message = Messages() message.messages = request.POST['message'] message.save() return redirect('messages') return render(request, 'app/messages.html', context) And this is my script: $(document).on('submit', '#new_message_form', function(e){ e.preventDefault(); $.ajax({ type: 'POST', url: '/messages/', data: { message: $('#message').val(), csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken').val(), }, success:function(){ alert("New message created!") } }); }); This results in MultiValueDictKeyError Instead I tried message.messages = request.POST.get('message', False) That only gets the value from the input and passes. But I cannot submit it without refreshing. Can anyone help me? -
How to create custom FileField which modifies the uploaded file in Django
I want to modify the contents of files when they are uploaded. I have many models using several FileFields that all need this behaviour so I don't want to use signals or override the model save() on each model. I want to create a custom FileField to handle this behaviour. I am trying to do this by extending FileField and overriding the pre_save() method. I am able to read the file contents but when I write to the file it remains unchanged. Below is a basic example. fields.py from django.db.models import FileField class CustomFileField(FileField): def pre_save(self, model_instance, add): file = super().pre_save(model_instance, add) file.write(b'foo') return file models.py from django.db import models from fields import CustomFileField class MyModel(models.Model): my_field = CustomFileField(upload_to='files') -
Auto Populated Fields Django
Auto populated forms Hello, My question is about populating field depending on other field. For example, I have form with 2 fields:PersonalNumber, FullName. Also I have Table in my sql database, which contains this two fields,(nealy 5mln rows) . I am wondering how can I achieve, When field(PersonalNumber) will be filled in my form, FullName has auto populated, by finding personalnumber in my database table and getting fullname from there. -
Reordering database after certain time period without harming dependencies in django
I'm wondering if is there any way to reorder whole database after a month or weeks in maintenance such that if my database has 10000+ of records and some in between records are deleted for example: records: 1,2,3,4,5,6,7,8,9 after deleting:1,2,5,8,9 after reordering:1,2,3,4,5 I'm using mysql as backend, and after reordering the dependencies between models must be retained such as ForeignKey, ManyToManyField -
how to order by date django post view
How can I order my posts from latest to oldest? I Use ordering = ['-date_posted'] for class based views. how can I do the exact thing for a function based view? this is my view function: def blog_view(request): posts = Post.objects.all() paginator = Paginator(posts, 3) page = request.GET.get('page') posts = paginator.get_page(page) common_tags = Post.tags.most_common()[:] context = { 'posts':posts, 'common_tags':common_tags, } return render(request, 'posts/blog.html', context) -
How to do render a database queryset in a Django base template?
I wish to display some queryset across all the pages in my website. From all indications, the logical thing to do is to include the tagging in the base.html. Unfortunately, the base.html is not been rendered or called by a url. So I am having tough time doing that. WHAT I HAVE DONE. 1 I made the query in a view that calls reders index.html. Passed the queryset into the context. Extended base.html in my index.html template used template tagging to call the queryset. It worked well in my local. but after deployment to heroku, it stopped displaying on my index. view.py from django.shortcuts import render, get_object_or_404 from .models import CompanyProfile, CompanyServices def index_view(request): company_services = CompanyServices.objects.all() company_profile = CompanyProfile.objects.all() context = { 'profile': company_profile, 'services': company_services, } return render(request, 'webpages/index.html', context=context) base.html snipptet <body> <!-- ======= Top Bar ======= --> <section id="topbar" class="d-none d-lg-block"> <div class="container d-flex"> <div class="contact-info mr-auto"> <i class="icofont-envelope"></i><a href="mailto:contact@example.com">{{profile.company_email}}</a> <i class="icofont-phone"></i> {{profile.company_phone1}} </div> How else can I make this work? -
IMAGE Upload in DRF, Imagefield cannot be serialized when introduce a checksum-gen method
I have an issue when try to upload image in DRF. Everything works fine with the following code. class UploadPhotoViewset( generics.CreateAPIView ): queryset = Photo.objects.all() parser_classes = (JSONParser, MultiPartParser, FormParser, FileUploadParser) serializer_class = PhotoSerializer def post(self, request, *args, **kwargs): print(request.data) img_file = request.data["image"] request.data["size"] = img_file.size request.data["title"] = img_file.name # request.data["checksum"] = self.get_file_md5(img_file) request.data["image"] = img_file print(request.data) return self.create(request, *args, **kwargs) But when I tried to generate the md5 hash for the file. Strange thing happens. class UploadPhotoViewset( generics.CreateAPIView ): queryset = Photo.objects.all() parser_classes = (JSONParser, MultiPartParser, FormParser, FileUploadParser) serializer_class = PhotoSerializer def post(self, request, *args, **kwargs): print(request.data) img_file = request.data["image"] request.data["size"] = img_file.size request.data["title"] = img_file.name # request.data["checksum"] = self.get_file_md5(img_file) request.data["image"] = img_file print(request.data) return self.create(request, *args, **kwargs) def get_file_md5(self, img): hash_md5 = hashlib.md5() for chunk in iter(lambda: img.read(4096), b""): hash_md5.update(chunk) return hash_md5.hexdigest() The data cannot be validated. serializer.is_valid(raise_exception=True) will give { "errors": { "image": [ "Upload a valid image. The file you uploaded was either not an image or a corrupted image." ] } } Anyone knows why? -
When I delete all the item's from my query in Django the item id's don't reset
I am a complete beginner and I'm creating my first Django webpage following Tech with Tim's tutorials. I have my first SQLite 3 database entry set up, but I can't seem to figure out why even when I delete every entry from it, when I add a new one it's id is still, for example, 10. Why aren't the id's resetting back to 0 when I delete everything from the query? I'm sorry if this question is badly worded or doesn't give enough information, as I said I'm a complete beginner and I'll try to edit my question however nescessary, thank you! -
Using HackerEarth API to integrate online compiler in Django
Trying to integrate an online compiler into my django project using the HackerEarth API this is the code I get when I run the project on local Access to 127.0.0.1 was denied You don't have authorization to view this page. HTTP ERROR 403 This is my views.py @login_required @student_required #From HackerEarth API def runCode(request): if request.is_ajax(): run_url = "https://api.hackerearth.com/v3/code/run/" source = request.POST['source'] lang = request.POST['lang'] data = { 'client_secret': '***', 'async': 0, 'source': source, 'lang': lang, 'time_limit': 5, 'memory_limit': 262144, } if 'input' in request.POST: data['input'] = request.POST['input'] r = requests.post(run_url, data=data) return JsonResponse(r.json(), safe=False) else: return HttpResponseForbidden() and html: {% load static %} <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Online Code Compiler</title> <script src="{% static 'fifth/js/jquery.min.js' %}" type="text/javascript" charset="utf-8"></script> <script src="{% static 'fifth/js/bootstrap.min.js' %}" type="text/javascript" charset="utf-8"></script> <script src="{% static 'fifth/js/ace.js' %}" type="text/javascript" charset="utf-8"></script> <script src="{% static 'fifth/js/ext-statusbar.js' %}" type="text/javascript" charset="utf-8"></script> <script src="{% static 'fifth/js/ext-language_tools.js' %}" type="text/javascript" charset="utf-8"></script> <script src="{% static 'fifth/js/customjs.js' %}" type="text/javascript" charset="utf-8"></script> <link rel="stylesheet" type="text/css" href="{% static 'fifth/css/bootstrap.min.css' %}" /> <link rel="stylesheet" type="text/css" href="{% static 'fifth/css/custom.css' %}" /> </head> <body> <input type="hidden" name="csrfmiddlewaretoken" value="{{ csrf_token }}" /> <nav class="navbar navbar-default"> <div class="container-fluid"> <div class="navbar-header"> <a style="color:#fff;"class="navbar-brand" href="#">HackerEarth</a> </div> <ul class="nav navbar-nav navbar-right"> … -
LookUpError: No installed app with label 'admin' and SyntaxError: {% extends 'base.html' %} in Django 2.0.2
I'm learning Python's Django library and working on product catalog type web page. I've revised all my code dozens of times and still, the root problem points at two error; Either SyntaxError: {% extends 'base.html' %} (this does not come always and I have revised my base.html files and accounts/templates login.html and signup.html files but there should not be syntax error). See Error2 picture to see error code This error comes only like 1-2 times out 10 python manage.py runserver. Mostly the error is LookUpError: No installed app with label 'admin' (see Error1 picture to see error code). PLEASE NOTE! I do have 'django.contrib.admin' in INSTALLED_APPS section of my settings.py file, located in 'producthunt' folder. I'm using Django 2.0.2 in my virtual environment. Tried to google both of these problems but they are not point at the root problem here. I'd appreciate very much if someone could revise my could revise my code behind this link: https://www.dropbox.com/s/lmgz9sii8ws4tkx/producthunt-project.7z?dl=0 Error1 'admin' error Error2 syntax error