django

Run both Django and PHP application in Apache

匆匆过客 提交于 2021-02-18 18:00:34
问题 I'm trying to host Django and PHP(wordpress) app in Apache domain.com, should point to Django app domain.com/wp, should point to wordpress app Here is my 000-default.conf in /etc/apache2/sites-available <VirtualHost *:80> DocumentRoot "/var/www/html/wp" ServerName domain.com/wp Alias /wp /var/www/html/wp <Directory /var/www/html/wp> Options Indexes FollowSymLinks AllowOverride None Order Deny,Allow Allow from all </Directory> </VirtualHost> <VirtualHost *:80> Alias /static /var/www/html

django - list of lists in template

一世执手 提交于 2021-02-18 17:57:06
问题 I am trying to render a list of lists zipped with zip() . list_of_list = zip(location,rating,images) I want to render this list_of_list to template and want to show only the first image of each location. my location and image models are these: class Location(models.Model): locationname = models.CharField class Image(models.Model): of_location = ForeignKey(Location,related_name="locs_image") img = models.ImageField(upload_to=".",default='') here is the zipped list. How can I access only the

django - list of lists in template

我们两清 提交于 2021-02-18 17:56:11
问题 I am trying to render a list of lists zipped with zip() . list_of_list = zip(location,rating,images) I want to render this list_of_list to template and want to show only the first image of each location. my location and image models are these: class Location(models.Model): locationname = models.CharField class Image(models.Model): of_location = ForeignKey(Location,related_name="locs_image") img = models.ImageField(upload_to=".",default='') here is the zipped list. How can I access only the

django image upload forms

时光总嘲笑我的痴心妄想 提交于 2021-02-18 17:53:05
问题 I am having problems with django forms and image uploads. I have googled, read the documentations and even questions ere, but cant figure out the issue. Here are my files my models class UserProfile(User): """user with app settings. """ DESIGNATION_CHOICES=( ('ADM', 'Administrator'), ('OFF', 'Club Official'), ('MEM', 'Ordinary Member'), ) onames = models.CharField(max_length=30, blank=True) phoneNumber = models.CharField(max_length=15) regNo = models.CharField(max_length=15) designation =

Can't connect to my AWS Database Instance | psql: could not connect to server: Operation timed out

泄露秘密 提交于 2021-02-18 17:08:17
问题 I created a postgres DB instance on AWS RDS. I am trying to connect this DB instance to my django zappa app so I can perform AWS Lambda functions. I've added a new security group to my DB instance so I can allow my django app to connect to it: My DB details show that the new security group is active: However when I try to connect to it, either by running psql --host="*************.us-east-2.rds.amazonaws.com" --port="5432" --username="*********" --password --dbname="*****" via my terminal, or

Model and Permissions

二次信任 提交于 2021-02-18 16:54:25
问题 I'm currently learning python/django As a Tutorial for myself I have done that: create user --> ok login user created --> ok create a new model called 'Article' with title and content as a properties --> ok create several 'Article' instances --> ok I display all the articles at the root of the webapp --> Last step is: in order to manipulate permission, only display some article depending on which user is logged with permissions. like if user A: then display only the article with odd ids (that

Django - Paginating in Template using multiple GET parameters

房东的猫 提交于 2021-02-18 15:40:21
问题 I am using a Django Paginator and I want to have multiple available get parameters, such as: page=1 sort_by=price However, in my template tags I have: Showing items sorted by {{ SORT_PARAM }}. Showing {{ ITEMS_PER_PAGE }} items per page. {% if has_prev %} <a href="?page={{ prev_page }}">Previous</a> | {% endif %} However, this does not preserve the other GET variables. What I mean is, if I'm viewing page/?page=1&sort_by=price and I click the link in the template fragment above, I will go to

Django - Paginating in Template using multiple GET parameters

心不动则不痛 提交于 2021-02-18 15:36:49
问题 I am using a Django Paginator and I want to have multiple available get parameters, such as: page=1 sort_by=price However, in my template tags I have: Showing items sorted by {{ SORT_PARAM }}. Showing {{ ITEMS_PER_PAGE }} items per page. {% if has_prev %} <a href="?page={{ prev_page }}">Previous</a> | {% endif %} However, this does not preserve the other GET variables. What I mean is, if I'm viewing page/?page=1&sort_by=price and I click the link in the template fragment above, I will go to

How to test signals when using factory_boy with muted signals

拜拜、爱过 提交于 2021-02-18 15:18:48
问题 I am using factory_boy package and DjangoModelFactory to generate a factory model with muted signals @factory.django.mute_signals(signals.post_save) class SomeModelTargetFactory(DjangoModelFactory): name = factory.Sequence(lambda x: "Name #{}".format(x)) ... I have a post_save signal connected to the model: def send_notification(sender, instance, created, **kwargs): if created: send_email(...) post_save.connect(send_notification, SomeModel) How can I test the signals works when I create an

Django DisallowedHost error

断了今生、忘了曾经 提交于 2021-02-18 12:26:53
问题 I'm running django with apache and I'm getting the following error in my apache error.log: django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'example.com'. You may need to add 'example.com' to ALLOWED_HOSTS., referer: http://example.com/ In my settings.py I have: ALLOWED_HOSTS = ['*'] This should allow any host shouldn't it? Edit: After some more investigating I've found out that no matter what I set ALLOWED_HOSTS to, it always results in the above error. I can reach the