How to insert data to django database from views.py file?

Your question is very unclear. You should probably go through the django-tutorial. But sure you can insert data into the db from views. Assume you have a model called Foo: models.py class Foo(models.Model): name = models.CharField(max_length=100) view.py from .models import Foo def some_name(request): foo_instance = Foo.objects.create(name=”test”) return render(request, ‘some_name.html.html’)

Union and Intersect in Django

You could use Q objects for #1: # Blogs who have either hockey or django tags. from django.db.models import Q Blog.objects.filter( Q(tags__name__iexact=”hockey”) | Q(tags__name__iexact=”django”) ) Unions and intersections, I believe, are a bit outside the scope of the Django ORM, but its possible to to these. The following examples are from a Django application called … Read more

Django 2.1.3 Error: __init__() takes 1 positional argument but 2 were given

You need use as_view() at the end of class based views when declaring in the urls: path(”, views.HomeView.as_view(), name=”homepage”), Also, when using login_required decorator, you need to use it on dispatch method of CBV: from django.contrib.auth.decorators import login_required from django.utils.decorators import method_decorator class HomeView(ListView): @method_decorator(login_required) def dispatch(self, *args, **kwargs): return super(HomeView, self).dispatch(*args, **kwargs)

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)