2018-10-22         Zara

Django uwsgi import error

I have a Django project with one app called subscribe. In root urls.py I use include from subscribe's urls.py.I put to INSTALLED_APPS subscribe and in subscribe's urls.py I use subscribe.views.<name> for call my views. When server run as python manage.py runserver locally all works fine. But when server run on nginx+uwsgi with virtualenv, I've got ImportError: No module named subscribe. When I changing subscribe to project.subscribe in INSTALLED_APPS and in subscribe's urls.py changing subscribe.views.<name> to project.subscribe.views.<name> all works fine...

 django                     1 answers                     31 view
 2018-10-22         Glenn

How to run multiple django sites on Nginx and uwsgi?

Is it possible to run multiple django sites on the same server using Nginx and uwsgi?I supposed its necessary to run multiple uwsgi instances (one for each site). I copied /etc/init.d/uwsgi to uwsgi2 and changed the port number. But, I got the following error:# /etc/init.d/uwsgi2 startStarting uwsgi: /usr/bin/uwsgi already running.How is possible to run multiple uwsgi instances?Thanks You can create create multiple virtual hosts that allow you to host multiple sites, independent from each other. More info here: http://wiki.nginx.org/VirtualHostExample.A bit more detailed...

 django                     4 answers                     33 view
 2018-10-22         Kelly

Websocket lost connection issue

This question already has an answer here: How to maintain a WebSockets connection between pages? 3 answers I would recommend you to use javascript to the maxmimum to make your DOM without loading a new page.Or you should seperate the websocket connection from web app and connect it with os-native functions. [XXX]

 django                     1 answers                     94 view
 2018-10-22         Vicky

502 Bad Gateway django nginx + gunicorn

I am using post request to load a big amount of data from user input (textarea) to the database(18k lines)And I get the 502 Bad Gateway errorWhen I print sudo nano /var/log/nginx/error.logI get this:2018/09/06 10:21:04 [alert] 19688#19688: *3 open socket #22 left in connection 42018/09/06 10:21:04 [alert] 19688#19688: aborting2018/09/06 11:04:32 [error] 20076#20076: *14 upstream prematurely closed connection while reading response header from upstream, client: 95.1$This is only on my production server (nginx + gunicorn + postgres), on my dev server it works great.What do I ...

 django                     1 answers                     61 view
 2018-10-22         Cecil

Django CBV - Formsets : 'NoneType' object has no attribute 'id'

I'm working with Django CBV and I'm trying to use formsets for the first time.I would like to fill two forms in the same time with a Foreign Key as common element between both.I have 2 models :class Publication(models.Model): title = models.CharField(max_length=512, verbose_name=_('title'), null=False, unique=True) description = models.TextField(verbose_name=_('description'), null=True) download_limit = models.IntegerField(verbose_name=_('download limit'), null=True) time_limit = models.IntegerField(verbose_name=_('expiration delay'), null=True) category = mo...

 django                     1 answers                     8 view
 2018-10-22         Muriel

django two class data in one table how to append

I want Mvouchar and Mycheque details append in one list that is reports, and field is also the same.Can I append this in one function? Because in my way it append only Mvouchars valueHow can I do this for both?views.pydef all_report(request): reports = [] for report_obj in Mvouchar.objects.all(): reports.append({'topay': report_obj.to_pay, 'chequeno': report_obj.cheque_no, 'chequedate': report_obj.cheque_date, 'date': report_obj.dated}) return render(request, 'cheque/report.html', {'reports': reports}) def all_report(request): rep...

 django                     2 answers                     17 view
 2018-10-22         Carey

How to use image that is stored to ImageField in the template?

I have the following the models.py:class Insurance(models.Model):area = models.CharField(max_length=100)title = models.CharField(max_length=50)insurance_type = models.CharField(max_length=50)area_photo = models.ImageField(upload_to='static/image')And this template: {% for product in insurance.insuranceproducts_set.all %} <li class="one_third btmspace-10 holder"> <figure><img src="{% static 'img/320x320.png' %}" alt=""> <div class="content"> <...

 django                     1 answers                     20 view
 2018-10-22         Edward

error :object can't be deleted because its id attribute is set to None

Trying to Delete an object using shell in django. How do i delete the object say "Ron"?I use the following command:t.delete('Ron') The error: object can't be deleted because its id attribute is set to NoneSuggests that you either never saved the object t in the first place, or you changed the primary key (here id) to None manually.If you have a single object you can perform a .delete() on the object, for example:my_obj = Model.objects.get(name='Ron')my_obj.delete()You should not add extra parameters to delete except for using and keep_parents, as specified in the docume...

 django                     1 answers                     93 view
 2018-10-22         Selena

Getting a Model dynamic by knowing its name

I use Django 2.1.I have a general utility/function(using celery) that I call from the save method of a Model(is an abstract Model, inherited by other Models).Because the data from the function will be serialize, I pass to it the Model name and PK.class A(models.Model) def save(self, *args, **kwargs): send_async(model_name=type(self).__name__, pk=self.id))class B(A)class C(A)Later, I want to query the Model, but I don't know how to get the Model:I tried: model = apps.get_model('django_app_name.{}'.format(model_name)) I get the following error:No installed app with labe...

 django                     3 answers                     95 view
 2018-10-22         Jack

Update an Object/Instance by overwriting the save method of another Model, by using the FK

I have the following models: class Acc(models.Model): name = models.CharField( max_length=35)class User(AbstractBaseUser, PermissionsMixin): acc = models.ForeignKey(Acc, blank=True, null=True, related_name='owner', on_delete=models.CASCADE)class Note(models.Model): name = models.CharField( max_length=35 receiver = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, on_delete=models.CASCADE)class Item(models.Model): note = models.ForeignKey(Notification, on_delete=models.CASCADE,) acc = models.ForeignKey(Acc, on_delete=models.CASCADE) ...

 django                     1 answers                     98 view
 2018-10-22         Mona

Getting a Model Foreign Key name and value?

I have the following model:class Item(models.Model): owner = models.ForeignKey(Owner, on_delete=models.CASCADE)I want to write a general function/utility to get the Foreign Key name and value passed it to another function as argument:In the code below I get the FKfor field in self._meta.get_fields(include_parents=False): if isinstance(field, models.ForeignKey):...........function f2 ({fk_name:value, fk_name2:value})How do I get the name(owner) and the value (owner_id) ? A ForeignKey object has an attribute, attname, that specifies the name of the attribute ...

 django                     2 answers                     100 view
 2018-10-22         Maud

Django CreateForm - redirect to same form on success

I have a page that contains a blog post, with a comment form above the list of comments, to allow users to add a comment.The blog post has the following url (where blog_id is a url parameter):/blog/<blog_id>Url pattern:urlpatterns = [ path('post/<blog_id>', BlogPostView.as_view(), name="BlogPostView"),]The view function:class BlogPostView(CreateView): template_name = 'blog_post.html' form_class = BlogCommentCreationForm success_url = ??? def get_context_data(self, *args, **kwargs): context = super().get_context_data(*args, **kwargs) ...

 django                     1 answers                     100 view
 2018-10-22         Genevieve

Resize image when uploading with Pillow using ModelForm

Hey I have a following code but, it return no error but the image is not being resized, at the beginning it was 6.2 MB and after running the code it is the same:My model:class Photo(models.Model): user_name= models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True) photo= models.ImageField() photo_name= models.TextField(max_length=300) def __str__(self): return self.photo_name def get_absolute_url(self): return reverse('photo:add_photo',{'pk':self.pk}) my Model.Formclass PhotoForm(ModelForm): def clean_image(self): img =...

 django                     2 answers                     101 view
 2018-10-22         Viola

Django: View with conditional login_required

Given the view, latest_objs, I wanted the view to require login conditionally if there is a parameter in the URL.The goal: If the URL passed is latest-objs, then return the non-authentication view with objs not related to any specific users.If the URL passed is latest-objs/mine, I want to require login if the user isn't authenticated, as that version of the view is supposed to return objs related to the authenticated user.Questions:Is the right way to do this to check request.GET.get('some-param')?How would I define these two scenarios in my urls.py file? Current I have thi...

 django                     1 answers                     6 view
 2018-10-22         Juliet

How to log exceptions and errors into a file when using a Django stand alone script

I have created a stand alone script in Django, but although the logging seems to be correctly configured, it fails to log the stderr into a Django log file. I am using Python 3.6 with Django 2.1.The content of the Django script my_script.py:import osimport djangoimport loggingos.environ['DJANGO_SETTINGS_MODULE'] = 'my_project.settings'django.setup()logger = logging.getLogger('my_script')def main(): logger.debug('This message is logged') raise Exception('Error messages (stderr) are NOT logged!')if __name__ == "__main__": main()My logging configuration in my_project/...

 django                     1 answers                     52 view
 2018-10-22         Alexander

Django saving modelformset_factory

When saving the formset, it is not validating and respecting the model fields that I have made unique and therefore renders an Integrity Error should I duplicate fields deliberately to test it.My guess is that the formsets themselves validate correctly, but as the unique field is something I have to assign during the save(commit=False) process it never gets validated. Does that make sense?Is there something I am missing please?My code:class ClientCreate(LoginRequiredMixin, FormView): def dispatch(self, *args, **kwargs): self.case = Case.objects.get(pk=kwargs['case...

 django                     1 answers                     51 view

Page 1 of 931  |  Show More Pages:  Top Prev Next Last