Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Autofill my author field with foreign key
I am trying to autofill my user foreign key in my note project with authentication in django. I tried, but it's not working and asking that owner is required field. Please, help! Thanks in an advance. views.py @login_required(login_url='login') def index(request): tasks = Task.objects.filter(owner=request.user) form = TaskForm() if request.method=='POST': form = TaskForm(request.POST) if form.is_valid(): instance = form.save(commit=False) instance.owner = request.user instance.save() context = { 'tasks':tasks, 'form':form, } return render(request, 'list.html',context) models.py class Task(models.Model): title = models.CharField(max_length=200) completed = models.BooleanField(default=False) created = models.DateTimeField(auto_now_add=True) owner = models.ForeignKey( settings.AUTH_USER_MODEL, on_delete=models.CASCADE ) def __str__(self): return self.title -
What is _set.all() in Django?
I'm going through one Django tutorial and in the Serializer _set.all() was used and I can't seem to figure out what does it do exactly. Here is the code snippet for this serializer: class OrderItemSerializer(serializers.ModelSerializer): class Meta: model = OrderItem fields = '__all__' class OrderSerializer(serializers.ModelSerializer): orders = serializers.SerializerMethodField(read_only=True) class Meta: model = Order fields = '__all__' def get_orders(self, obj): items = obj.orderitem_set.all() serializer = OrderItemSerializer(items, many=True) return serializer.data -
Problem with deleting cache in localized page
I have pages to view posts. Also I have header with option to switch language and when I switch language, it changes on all pages, except pages with cache. There language changes only when I reboot the server. I need to understand, how I can delete cache, when I change language. Views.py: class DetailPostView(generic.DetailView): def get(self, request, *args, **kwargs): pk = kwargs['pk'] post = Post.objects.get(pk=pk) comments = Comment.objects.filter(post=post) form = CommentForm() context = { "post": post, 'comments': comments, 'form': form, } return render(request, "detail_post.html", context) def post(self, request, pk): post = Post.objects.get(pk=pk) comments = Comment.objects.filter(post=post) form = CommentForm(request.POST) if form.is_valid(): author = self.check_user_authenticated(request, form) comment = Comment( author=author, body=form.cleaned_data['body'], image=form.cleaned_data['image'] if 'image' in form.cleaned_data else None, post=post, user=request.user if isinstance(request.user, User) else None ) comment.save() context = {'post': post, 'comments': comments, 'form': form} return render(request, "detail_post.html", context) def check_user_authenticated(self, request, form): if request.user.is_authenticated: author = request.user.profile.name elif form.cleaned_data['author']: author = form.cleaned_data['author'] else: author = 'Anonim' return author Models.py: class Post(models.Model): title = models.CharField(max_length=25) body = models.TextField() image = models.ImageField(blank=True, upload_to=post_directory_path) created_on = models.DateTimeField(auto_now_add=True) last_modified = models.DateTimeField(auto_now=True) categories = models.ManyToManyField('Category', related_name='posts', blank=True) profile = models.ForeignKey('Profile', verbose_name='User', on_delete=models.CASCADE, related_name='profile') def __str__(self): return self.title @receiver(post_save, sender=Post, dispatch_uid="clear_cache_post") def update_post(sender, **kwargs): key = make_template_fragment_key('post', … -
Celery Worker Not Running Tasks When Scheduled(Using Supervisor)
I have configured by VPS server with Django and I am running a scheduled task for that I am using CELERY. I am using supervisor to run celery. When I directly run the celery command all the things work great and my schedule jobs also work(also if I click on run task button the tasks start quickly). But when I configured celery using supervisor it never runs the tasks (when scheduled) and also the run task did not work at the first time(when I try 4-5 times the tasks start it runs). This is my supervisor file- ; ================================== ; celery worker supervisor example ; ================================== ; the name of your supervisord program [program:ip_tambola] #Set full path to celery program if using virtualenv command=/home/django/venv/bin/celery -A Tambola worker --beat --scheduler django_celery_beat.schedulers:DatabaseScheduler --loglevel=debug #The directory to your Django project directory=/home/django/ip_tambola/Tambola #If supervisord is run as the root user, switch users to this UNIX user account before doing any pr user=root #Supervisor will start as many instances of this program as named by numprocs numprocs=1 #Put process stdout output in this file stdout_logfile=/home/django/ip_tambola/celery_out.log #Put process stderr output in this file stderr_logfile=/home/django/ip_tambola/celery_err.log #If true, this program will start automatically when supervisord is started autostart=true … -
Failed to import mp3 file using mutagen in Django
I'm trying to get the length of an mp3 file using mutagen in django. (Finding the length of an mp3 file) I saw and followed the post above. I installed mutagen with pip and wrote the code like this: def music_player(request, id): song = Song.objects.get(id=id) audio = MP3(song.song) print(audio.info.length) There was an error loading the mp3 file. error code: FileNotFoundError: [Errno 2] No such file or directory: '/Users/<username>/django/note/media/media/song/butter.mp3' The file path is incorrect. 'Media/Media'. It seems that the media path was added automatically once more. (song.song has a built-in 'media/song/butter.mp3'.) How can I solve this? -
How i can pass value of html element to model.py in django?
How i can get value of checkbox from customize html in model.py or admin.py? # model.py class Geo(models.Model): locations = models.TextField(blank = True, null = True) location_as_text = models.TextField(blank = True, null = True) def save(self, *args, **kwargs): answer = value_of_check_box_in_custom_html if answer = true: func1() else: func2() super(taxon, self).save(*args, **kwargs) I have custom_change_form.html in admin templates # admin/personal/custom_change_form.html {% extends "../change_form.html" %} {% load i18n admin_urls static admin_modify %} {% block submit_buttons_bottom %} <div class="form-check form-switch"> <input class="form-check-input" type="checkbox" id="flexSwitchCheckChecked" checked name="locationcheck"/> <label class="form-check-label" for="flexSwitchCheckChecked">Checked switch checkbox input</label> </div> {% submit_row %} {% endblock %} My admin.py # admin.py @admin.register(models.geo) class geoAdmin(admin.ModelAdmin): change_form_template = 'admin/personal/custom_change_form.html' def get_osm_info(self): # ... pass def change_view(self, request, object_id, form_url='', extra_context=None): extra_context = extra_context or {} extra_context['osm_data'] = self.get_osm_info() return super().change_view( request, object_id, form_url, extra_context=extra_context, ) How do I check whether a checkbox is checked in customize html? -
App not compatible with buildpack: Django + Python
When I click deployed button on heroku, I get some error, I have deployed this project for a certain period of time, and this time I deployed this error: -----> Building on the Heroku-18 stack -----> Using buildpack: heroku/python -----> App not compatible with buildpack: https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/python.tgz More info: https://devcenter.heroku.com/articles/buildpacks#detection-failure ! Push failed I already have requirnments.txt, runtime.txt, Procfile, I already added buildpack(heroku/python) in setting, requirnments.txt asgiref==3.2.10 beautifulsoup4==4.9.3 dj-database-url==0.5.0 dj-static==0.0.6 Django==3.1.1 gunicorn==20.0.4 Pillow==8.1.2 psycopg2-binary==2.8.6 pytz==2020.1 soupsieve==2.2.1 sqlparse==0.3.1 static3==0.7.0 runtime.txt python-3.7.3 Procfile web: gunicorn APP_NAME.wsgi --log-file - Any help or explanation is welcome! Thank you. -
There is a way to {% extends '' %} parent html from alternative folder in template?
My project has several customers. Each app has html files that need to be specific for that customer, althogh has the same name. My approach to solve this was a variable which holds the folder's name with customer's html files, before the template's path, with this: {% extends {{FOLDER_NAME}}'account/form/base.html' %} instead this: {% extends 'account/form/base.html' %}, off course this d'ont work and I was wondering if there is a way to solve this. Thanks in advance. -
django static files are not being found and loaded
Using django v2.2.1 I have a given project dir. structure: In root project dir. there are some static files in static dir. In base.html file, {% load static %} <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- favicon --> <link rel="shortcut icon" href="{% static 'favicon.ico' %}" /> <!-- Dropzone js --> <link rel="stylesheet" href="{% static 'dropzone.css' %}"> <script src="{% static 'dropzone.js' %}" defer></script> <!-- Custom js & css --> <link rel="stylesheet" href="{% static 'style.css' %}"> . . This is settings.py file: # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.2/howto/static-files/ STATIC_URL = '/static/' STATICFILES_DIR = [ os.path.join(BASE_DIR, 'static'), os.path.join(BASE_DIR, 'sales', 'static'), ] MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') But I've been getting this error I have restarted the server many times. -
how to capture logged in user's name in django?
class logEngine: def logger(request): t1 = time.time() params = {'user': request.user.username, 'ip_address': socket.gethostbyname(socket.gethostname()), 'process_time': time.time() - t1, } return params when I uses request.user.username (which is given in most of the examples in the internet), I get the below error, AttributeError: 'logEngine' object has no attribute 'user' Please suggest any other method -
Regarding user authentication
When the user is logged in or logged out the user must see and can fill the feedback page.How can I do it?Feedback page -
Sending Mail configuration in django
I am facing a problem when trying to test sending a message from the django app, but I get this error message : SMTPAuthenticationError at /accounts/contact_us (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8 https://support.google.com/mail/?p=BadCredentials f13sm16175910wrt.86 - gsmtp') And I looked for all the possible solutions like : Enable two-step verification , Enable less secure app access settings . But it was in vain and did not work successfully. Could anyone help please ? this is my settings : EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_HOST_USER = 'myname@gmail.com' EMAIL_HOST_PASSWORD = '****************' EMAIL_USE_TLS = True EMAIL_PORT = 587 this is my views.py: def contact_us(requset): subject = requset.POST.get('subject', '') message = requset.POST.get('message', '') from_email = requset.POST.get('from_email', '') send_mail(subject, message, from_email, ['myname@gmail.com']) return render( requset , 'accounts/contact_us.html' ) this is my contact_us.html: <div class="contact_form"> <form name="contact_form" action="" method="POST"> {% csrf_token %} <p><input type="text" name="subject" class="name" placeholder="subject" required></p> <p><textarea name="message" class="message" placeholder="message" required></textare></p> <p><input type="text" name="from_email" class="email" placeholder="email" required></p> <p><input type="submit" value="sent" class="submit_btn"></p> </form> </div> -
djang_.template_exception_TemplateDoesNotExist
TemplateDoesNotExist at /manager manager/templates/login.html Request Method: GET Request URL: http://127.0.0.1:8000/manager Django Version: 3.1.1 Exception Type: TemplateDoesNotExist Exception Value: manager/templates/login.html Exception Location: C:\Users\Microsoft\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\template\loader.py, line 19, in get_template Python Executable: C:\Users\Microsoft\AppData\Local\Programs\Python\Python37-32\python.exe Python Version: 3.7.3 Python Path: ['E:\Project\Debugger', 'C:\Users\Microsoft\AppData\Local\Programs\Python\Python37-32\python37.zip', 'C:\Users\Microsoft\AppData\Local\Programs\Python\Python37-32\DLLs', 'C:\Users\Microsoft\AppData\Local\Programs\Python\Python37-32\lib', 'C:\Users\Microsoft\AppData\Local\Programs\Python\Python37-32', 'C:\Users\Microsoft\AppData\Roaming\Python\Python37\site-packages', 'C:\Users\Microsoft\AppData\Local\Programs\Python\Python37-32\lib\site-packages', 'C:\Users\Microsoft\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32', 'C:\Users\Microsoft\AppData\Local\Programs\Python\Python37-32\lib\site-packages\win32\lib', 'C:\Users\Microsoft\AppData\Local\Programs\Python\Python37-32\lib\site-packages\Pythonwin'] Server time: Sun, 20 Jun 2021 13:58:39 +0000 Template-loader postmortem Django tried loading these templates, in this order: Using engine django: django.template.loaders.filesystem.Loader: E:\Project\Debugger\templates\manager\templates\login.html (Source does not exist) django.template.loaders.app_directories.Loader: C:\Users\Microsoft\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\admin\templates\manager\templates\login.html (Source does not exist) django.template.loaders.app_directories.Loader: C:\Users\Microsoft\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\auth\templates\manager\templates\login.html (Source does not exist) django.template.loaders.app_directories.Loader: E:\Project\Debugger\manager\templates\manager\templates\login.html (Source does not exist) django.template.loaders.app_directories.Loader: E:\Project\Debugger\welcome\templates\manager\templates\login.html (Source does not exist) django.template.loaders.app_directories.Loader: C:\Users\Microsoft\AppData\Roaming\Python\Python37\site-packages\phone_field\templates\manager\templates\login.html (Source does not exist) -
How can i update a field in django with javascript
my project is about bidding when the product time is up then it should be automatically saved to a orders table please help me to solve with any way that you know models.py class products(models.Model): produtname=models.CharField(max_length=255) productdesc=models.CharField(max_length=255) amount=models.FloatField() image=models.ImageField(upload_to='pics') featured=models.BooleanField(default=False) enddate=models.DateTimeField() class orders(models.Models): product_id=models.IntegerField() user_id=models.IntegerField() i wanted to update the orders table automatically when the products tables endate is finished can you please suggest me any way to do this. -
Django import export when we have name of data when importing foreign key but not the id
I am having a csv file with the data which includes name of the user who will import the data, which is basically a foreign key. When I try to import the csv file. I am not able to import the csv file with the name of the foreign key (with the username of the user) . This is my models.py where I am taking a field which will take the input of the logged in user if the form is filled via UI. However to import the data in bulk, I should be able to give the username of the user who is importing the data and not the foreign key which is an integer value. models.py class Vendor(models.Model): ... added_by_user = models.ForeignKey(User, on_delete=models.PROTECT, related_name= "vendors", verbose_name="Added By User") ... This is my admin.py from django.contrib import admin from app.models import Vendor from import_export import resources from import_export.admin import ImportExportModelAdmin from django.contrib.auth.models import User class VendorResource(resources.ModelResource): class Meta: model = Vendor fields = ('added_by_user__username',) @admin.register(Vendor) class VendorAdmin(ImportExportModelAdmin): pass I am new to this and I think I am missing on something, I have followed everything as mentioned here in documentation. Please help me find the correct option so that … -
Creating django notifications using signals
I am trying to create django notifications using signals. Any user can add a question, add a solution to that question and comment on each solution. So I have this in models.py: class Log(models.Model): title = models.CharField(blank=False, max_length=500) content = models.TextField(blank=False) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) slug = models.SlugField(max_length=50, null=False, unique=True) author = models.ForeignKey(User, on_delete=models.CASCADE,null=True, blank=True) image = models.ImageField( upload_to='images', blank=True) def save(self, *args, **kwargs): super().save() self.slug = self.slug or slugify(self.title + '-' + str(self.id)) super().save(*args, **kwargs) class Meta: verbose_name = ("Log") verbose_name_plural = ("Logs") def __str__(self): return f"{self.title}" def get_absolute_url(self): return reverse("log-detail", kwargs={"question": self.slug}) class Notification(models.Model): notification_for = models.CharField(null=True, blank=True,max_length=50) user = models.ForeignKey(Log, on_delete=models.CASCADE,null=True, blank=True) I want to create notification when someone adds a question, or solution or comments Do I have to create separate Notification model for each type of notif? signals.py: from django.db.models.signals import post_save from django.contrib.auth.models import User from django.dispatch import receiver from .models import Log, Notification @receiver(post_save, sender=Log) def create_notif(sender, instance, created, **kwargs): if created: Notification.objects.create(author=instance.author, notification_for='log created') -
get results of running a task on Celery (Windows 10 32 bits)
I've been working around this problem for about 10 hours since morning but couldn't find any solutions to that. I'm learning to use Celery. I want to use it in one of my django projects. I followed the official tutorials but I can't get the results of my tasks back. no matter the backend is configured or not, I always get this error when trying to access the results: Traceback (most recent call last): File "<console>", line 1, in <module> File "G:\progs\python\Django-projects\celery_tutorial\env\lib\site-packages\celery\result.py", line 223, in get return self.backend.wait_for_pending( File "G:\progs\python\Django-projects\celery_tutorial\env\lib\site-packages\celery\backends\base.py", line 698, in wait_for_pending meta = self.wait_for( File "G:\progs\python\Django-projects\celery_tutorial\env\lib\site-packages\celery\backends\base.py", line 1029, in _is_disabled raise NotImplementedError(E_NO_BACKEND.strip()) NotImplementedError: No result backend is configured. Please see the documentation for more information. Here is my folder structure: |- task_exe |- celery.py |- settings.py |- ... |- tadder |- tasks.py |- ... |- env |- manage.py |- ... this is my celery.py file: from __future__ import absolute_import, unicode_literals from celery import Celery from tadder.tasks import add import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'task_exe.settings') app = Celery("task_exe", backend='rpc://' , broker='amqp://localhost') app.config_from_object('django.conf:settings', namespace="CELERY") app.autodiscover_tasks() this is my tasks.py file: from __future__ import absolute_import, unicode_literals from celery import shared_task @shared_task def add(a, b): return a + b and this is the … -
How to access database table with primary key in Django SQLite3 database
In my Django app, I'm adding a search feature that will search the posts database and return matching results. After a few Google searches, I discovered that we can search using "example contains='example'." It works, but it only returns the title of the results; I can't figure out how do I get the description of a post whose title I know? This is the source code: views.py: def results(request): match_title = Posts.objects.filter(Q(title__contains='Pets')) context = { 'results': match_title } return render(request, 'blog/results.html', context) models.py: class Posts(models.Model): id = models.BigAutoField(primary_key=True) title = models.CharField(max_length = 100) desc = models.CharField(max_length = 1000) def __str__(self): return f'{self.title}' results.html: {% if links %} {% for result in results %} <div class="result-group results-container"> <small class="result-link">{{ result.url }}</small> <h2 class="result-title">{{ result.title }}</h2> <h5 class="result-desc">{{ result.desc }}</h5> </div> <br> {% endfor %} {% else %} <div class="result-group results-container"> <p>Sorry, we are not able to find what you are looking for.</p> </div> {% endif %} How do I get the description of a post whose title I know? Please assist. -
django validating a field even when a depending field is empty
I am trying to validate two depending fields such that, if a checkbox is checked, then validate the URL field, but if the checkbox is not checked, do not validate the URL field. Using clean() I have a code that looks like this: models.py class MyModel(models.Model): chkbk = MultiSelectField(max_length=15, choices=choices.SOME_CHOICES, blank=True, null=True) url_field = models.URLField(max_length=200, blank=True, null=True) form.py def clean(self): cleaned_data = super().clean() chkbk = cleaned_data.get('chkbk') url_field = cleaned_data.get('url_field') if chkbk and url_field is None: self.add_error('chkbk', ValidationError("Fix this error")) The logic works if the user checks box and submit a valid URL the user checks box and leaves url field empty, error message the user unchecks box and leaves url field empty But, when the user unchecks the box but have invalid url in the url field, the for does not submit, because regardless of the validation checks, the url field will still try to submit to the database, which is an expected behaviour. Is there a way to not validate the URL field if checkbox is unchecked or set the value of that field to empty/null/None in clean just before submitting the form so validation on the url field can pass if the checkbox it depends on is not … -
how to filter on a reversed relationship on Django?
I have this two models: class Company(models.Model): name = models.CharField(max_length=255) created_at = models.DateTimeField() class Employee(models.Model): name = models.CharField(max_length=255) incorporated_at = models.DateTimeField() company = models.ForeignKey(Company, on_delete=models.CASCADE, related_name="employees") If I do the following reversed lookup: Company.objects.filter(employees__incorporated_at="2021-01-01T00:00:00+00:00") Then I'll get a list of those companies with at least one employee that satisfies such a query. But what I want to get is a list of companies with all its employees satisfying that query. How can I do it? -
Django Pyrebase retrieving from firebase using infinite scroll
I'm a bit stuck on how best to approach this problem. I currently have data being pulled in from Firebase and use django paginator with jquery and waypoints to get an infinite scroll. However, the def innovations_view currently returns all the entries in the database. I want it to return the first 5 then on scroll load another 5. I believe I may need to add a listener, but not sure how best to approach it. Any help would be greatly appreciated. views.py def innovations_view(request): db_name = database.child('1aBDytzaM232X_H3tjTuanG8-jxiEn0rg5_pg_cvnbgw') object_list = db_name.child('Sheet1').get().val() page = request.GET.get('page', 1) paginator = Paginator(object_list, 5) try: objects = paginator.page(page) except PageNotAnInteger: objects = paginator.page(1) except EmptyPage: objects = paginator.page(paginator.num_pages) context = { "object_list": objects, } return render(request, 'list.html', context) list.html {% extends 'base.html' %} {% block content %} {% load static %} <div class="container-fluid"> <div class="row row-cols-1 row-cols-md-3 g-4 infinite-container"> {% for instance in object_list %} <div class="col infinite-item"> <div class="card h-100"> <img src="{{ instance.featureimg}}" class="card-img-top" alt="..."> <div class="card-body"> <h5 class="card-title">{{ instance.title }}</h5> <p class="card-text">{{ instance.summary|truncatewords:20 }}</p> </div> </div> </div> {% endfor %} </div> <div class="spinload position-fixed" style="display: none; top:35vh; left:46vw;"> <div class="spinner-border" role="status"> <span class="visually-hidden">Loading...</span> </div> </div> <div> {% if object_list.has_next %} <a class="infinite-more-link" href="?page={{ … -
i want to generate short link and render it to templates using pyshorteners
I want to convert my full url to short url using pyshorteners and render to every detail templates of the link . Here, i am giving below, the views and the link template, with the url patterns. Below is my Views.py: import pyshorteners def get_absolute_url(request): link = request.get_full_path() shortener = pyshorteners.Shortener() short_link = shortener.tinyurl.short(link) return reverse('link', {"link": short_link}) Below is my Link Template: <!-- Copy to Clipboard --> <center> <label for="text_copy" class="text-primary">Link to be shared</label> <input type="text" class="form-control border-0 d-block bg-dark text-white" id="text_copy" value="{{ request.build_absolute_uri }}"/> <div class="container"> <button onclick="copyToClipboard('#text_copy')" type="button" class="col mr-3 btn btn-light btn-rounded" data-mdb-ripple-color="dark">Copy</button> </div> </center> <!-- Copy to Clipboard --> <center> <label for="text_copy" class="text-primary"> Short Link to be shared</label> <input type="text" class="form-control border-0 d-block bg-dark text-white" id="text_copy1" value='{{ link.short_link }}'/> <div class="container"> <button onclick="copyToClipboard('#text_copy1')" type="button" class="col mr-3 btn btn-light btn-rounded" data-mdb-ripple-color="dark">Copy</button> </div> </center> As I am trying to convert my url to short url, I also tried using python function to also create a short link. Below is how the pyshorteners function module is working. import pyshorteners link = input("Enter the link:") Enter the link:>? http://127.0.0.1:8000/affiliation/link/10003/ shortener = pyshorteners.Shortener() x = shortener.tinyurl.short(link) print(x) h__ps://tinyurlcom/yfzx7uxm #this is the short link i have received and its working. #Also … -
Connect local database in heroko using django
I want don't want to use the Heroku database instead I want to use my local database in the Heroku server. so how do I connect my local database to Heroko. -
Can't I save data in django model from files other than views?I am getting this error
I want to save data in a model. Lets say I want to hard code data from views.py it saves but when i try to do it by creating a seperate file it doesn't. It doesnt import models at all giving error ImportError: attempted relative import with no known parent package.Am I missing something here : I have tried doing: from .models import className from models import className from . import models and calling models.className -
Unable to show user specific link to specific page in django
I would like to create user specific links. I mean, when user signed up and logged in, he has redirected to create/ page. In that page user fills out the form and after pressing button, user has to redirect to list/ page, where there are user specific links to specific page, which contain schedule. Schedul appered from data, which user provided in create/ form. So my problem is, when I filled out the form and redirect to list/ page, there are no links. My code: models.py from django.db import models from django.contrib.auth.models import User class File(models.Model): file = models.OneToOneField(User, on_delete=models.CASCADE, null=True) #Further, they are fileds, which is nececary to create schedule. #title = models.CharField('Название Графика', max_length = 50) #x_title = models.CharField('Название Оси Х', max_length = 50) #y_title = models.CharField('Название Оси Y', max_length = 50) #etc... views.py: def create(request): error = '' if request.method == 'POST': form = FileForm(request.POST) if form.is_valid(): form.save() return redirect('grafic:list') else: error = 'Форма была неверной(' form = FileForm() data = { 'form': form, 'error': error, } return render(request, 'graf/create.html', data) def list(request): qs = File.objects.filter(file=request.user) context = { 'user': request.user, 'qs': qs, } return render(request, 'graf/list.html', context) list.html {% extends 'base.html' %} {% block content %} …