-
Posts
10 -
Joined
-
Last visited
Posts posted by formigol
-
-
Yes the error is still there
-
Hello!
My django app was working very well and at certain point (without any change in the code) this error emerged:
'function' object has no attribute 'as_view'
Exception Location: /home/formigol/public_html/contacts/urls.py in <module>, line 6This is the code line of the error location:
url(r'^add_contact_1$', views.AddContactFormView.as_view(), name='add_contact'),
where the views.AddContactFormView is a class based view thet has out of the box the methos .as_view().
I think that this is a server problem. What do you suggest to do?
Do you think that the problem is similar to the following?
Thanks a lot for your help!
-
The Google settings were not enough for me. The only way I found to solve the problem was the django library.
-
Hello!
Good news for django users! The django smtp built in library works! Here is the link to the documentation:
https://docs.djangoproject.com/en/2.0/topics/email/#django.core.mail.backends.smtp.EmailBackend
-
Hello!
I am using django on Tommy. In one of my django apps I would like to connect to my google mail trough "smtp.gmail.com",587 and send some emails. When I try to do this the following error arise:
[Errno 101] Network is unreachable
I think that is a firewall issue. Is possible to solve this problem?
the script that I wrote is the following:
#! /usr/bin/python # -*- coding: utf-8 -*- from __future__ import unicode_literals import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from .models import Story from django.utils import timezone def send_mail(html, destination): gmail_pwd = '********' # me == my email address # you == recipient's email address me = "colouredsweat@gmail.com" smtpserver = smtplib.SMTP("smtp.gmail.com",587) smtpserver.ehlo() smtpserver.starttls() smtpserver.ehlo smtpserver.login(me, gmail_pwd) header = 'To:' + destination.email + '\n' + 'From: ' + me + '\n' + 'Subject:Coloured Sweat \n' #print header # Create message container - the correct MIME type is multipart/alternative. msg = MIMEMultipart('alternative') msg['Subject'] = "Coloured Sweat" msg['From'] = me msg['To'] = destination.email # Create the body of the message (a plain-text and an HTML version). text = 'hey' # Record the MIME types of both parts - text/plain and text/html. part1 = MIMEText(text, 'plain') part2 = MIMEText(html, 'html') # Attach parts into message container. # According to RFC 2046, the last part of a multipart message, in this case # the HTML message, is best and preferred. msg.attach(part1) msg.attach(part2) smtpserver.sendmail(me, destination.email, msg.as_string()) #print 'done!' smtpserver.close()
-
Ok. I will write everything I have done until now following a tutorial structure; maybe it will be useful for future Django users on Heliohost:
1. I started the project from scratch using the cookiecutter.
2. Than I uncommented the following commented lines in the project_name/urls.py. That generate an admin log-in page at the URL http://www.your_name.heliohost.org/project_name/admin
from django.conf.urls import url #from django.contrib import admin urlpatterns = [ #url(r'^admin/', admin.site.urls), ]
3. At this point I visited the page and I noticed that the css was not working (see the discussion before)
4. I collected all the static files of my project located on my personal computer. To do that:
--> first I added the following two lines in my project_name/settings.py file
STATIC_URL = '/static/' # url that django uses to find the static files while the server is running STATIC_ROOT = '/path/to/my/project/folder/static' #url that says to django were to collect all the statics (on the local host)
--> than in the terminal I typed the following command to collect all the static in the URL_ROOT.
./manage.py collectstatics
--> I made a .tar file and deployed everything on the server.
4. The next step is to create a superuser to test the admin application
and there is were the problems are coming out.
--> I created the superuser on my local host. (from now on after every change on my local host I deployed the new version on the server trough filemanager)
./manage.py createsuperuser
Everything worked on the server until I tried to login with my new super user. At this point django show me an error page saying that: Django Attempt to write a read-only database.
I tried to change the permissions of the database (the file called db.sqlite3) to 777 and the django error trasformed into: unable to open database file
The complete ERROR OUTPUT:
Environment: Request Method: POST Request URL: http://www.colouredsweat.heliohost.org/colswe2/admin/login/?next=/colswe2/admin/ Django Version: 1.11.6 Python Version: 3.6.3 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware'] Traceback: File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/base/base.py" in ensure_connection 213. self.connect() File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/base/base.py" in connect 189. self.connection = self.get_new_connection(conn_params) File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py" in get_new_connection 198. conn = Database.connect(**conn_params) The above exception (unable to open database file) was the direct cause of the following exception: File "/usr/local/python3.6/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner 41. response = get_response(request) File "/usr/local/python3.6/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 187. response = self.process_exception_by_middleware(e, request) File "/usr/local/python3.6/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 185. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/python3.6/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 57. response = view_func(request, *args, **kwargs) File "/usr/local/python3.6/lib/python3.6/site-packages/django/contrib/admin/sites.py" in login 393. return LoginView.as_view(**defaults)(request) File "/usr/local/python3.6/lib/python3.6/site-packages/django/views/generic/base.py" in view 68. return self.dispatch(request, *args, **kwargs) File "/usr/local/python3.6/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper 67. return bound_func(*args, **kwargs) File "/usr/local/python3.6/lib/python3.6/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper 76. return view(request, *args, **kwargs) File "/usr/local/python3.6/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func 63. return func.__get__(self, type(self))(*args2, **kwargs2) File "/usr/local/python3.6/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper 67. return bound_func(*args, **kwargs) File "/usr/local/python3.6/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view 149. response = view_func(request, *args, **kwargs) File "/usr/local/python3.6/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func 63. return func.__get__(self, type(self))(*args2, **kwargs2) File "/usr/local/python3.6/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper 67. return bound_func(*args, **kwargs) File "/usr/local/python3.6/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 57. response = view_func(request, *args, **kwargs) File "/usr/local/python3.6/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func 63. return func.__get__(self, type(self))(*args2, **kwargs2) File "/usr/local/python3.6/lib/python3.6/site-packages/django/contrib/auth/views.py" in dispatch 90. return super(LoginView, self).dispatch(request, *args, **kwargs) File "/usr/local/python3.6/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch 88. return handler(request, *args, **kwargs) File "/usr/local/python3.6/lib/python3.6/site-packages/django/views/generic/edit.py" in post 182. if form.is_valid(): File "/usr/local/python3.6/lib/python3.6/site-packages/django/forms/forms.py" in is_valid 183. return self.is_bound and not self.errors File "/usr/local/python3.6/lib/python3.6/site-packages/django/forms/forms.py" in errors 175. self.full_clean() File "/usr/local/python3.6/lib/python3.6/site-packages/django/forms/forms.py" in full_clean 385. self._clean_form() File "/usr/local/python3.6/lib/python3.6/site-packages/django/forms/forms.py" in _clean_form 412. cleaned_data = self.clean() File "/usr/local/python3.6/lib/python3.6/site-packages/django/contrib/auth/forms.py" in clean 187. self.user_cache = authenticate(self.request, username=username, password=password) File "/usr/local/python3.6/lib/python3.6/site-packages/django/contrib/auth/__init__.py" in authenticate 70. user = _authenticate_with_backend(backend, backend_path, request, credentials) File "/usr/local/python3.6/lib/python3.6/site-packages/django/contrib/auth/__init__.py" in _authenticate_with_backend 115. return backend.authenticate(*args, **credentials) File "/usr/local/python3.6/lib/python3.6/site-packages/django/contrib/auth/backends.py" in authenticate 18. user = UserModel._default_manager.get_by_natural_key(username) File "/usr/local/python3.6/lib/python3.6/site-packages/django/contrib/auth/base_user.py" in get_by_natural_key 48. return self.get(**{self.model.USERNAME_FIELD: username}) File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/models/manager.py" in manager_method 85. return getattr(self.get_queryset(), name)(*args, **kwargs) File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/models/query.py" in get 374. num = len(clone) File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/models/query.py" in __len__ 232. self._fetch_all() File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/models/query.py" in _fetch_all 1118. self._result_cache = list(self._iterable_class(self)) File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/models/query.py" in __iter__ 53. results = compiler.execute_sql(chunked_fetch=self.chunked_fetch) File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/models/sql/compiler.py" in execute_sql 882. cursor = self.connection.cursor() File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/base/base.py" in cursor 254. return self._cursor() File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/base/base.py" in _cursor 229. self.ensure_connection() File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/base/base.py" in ensure_connection 213. self.connect() File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/utils.py" in __exit__ 94. six.reraise(dj_exc_type, dj_exc_value, traceback) File "/usr/local/python3.6/lib/python3.6/site-packages/django/utils/six.py" in reraise 685. raise value.with_traceback(tb) File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/base/base.py" in ensure_connection 213. self.connect() File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/base/base.py" in connect 189. self.connection = self.get_new_connection(conn_params) File "/usr/local/python3.6/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py" in get_new_connection 198. conn = Database.connect(**conn_params) Exception Type: OperationalError at /admin/login/ Exception Value: unable to open database file
What do you suggest to solve the problem? Maybe I should use a database provided by heliohost and not the one created on my local host?
Thanks in advance for your help!
-
Hello and happy new year!
First: Thanks a lot for your help!
I'm still having a lot of problems and I'm still not able to deploy my apps on tommy... I'm missing something... when I try to deploy a simple djangotest app (following the instructions online) more or less it works (the css problem that you already told me how to solve) but when I try to install an application that I developed on my PC everything goes crazy and nothing works. I get the following errors:
[Thu Jan 04 15:52:02.260254 2018] [core:info] [pid 14573:tid 140340614858496] [client 93.34.147.76:42047] AH00128: File does not exist: /home/formigol/public_html/500.shtml [Thu Jan 04 15:52:02.259885 2018] [wsgi:error] [pid 14573:tid 140340614858496] [client 93.34.147.76:42047] File "/home/formigol/public_html/contacts/models.py", line 29 [Thu Jan 04 15:52:02.259668 2018] [wsgi:error] [pid 14573:tid 140340614858496] [client 93.34.147.76:42047] File "/home/formigol/public_html/colswe/dispatch.wsgi", line 11, in <module> [Thu Jan 04 15:52:02.258313 2018] [wsgi:error] [pid 14573:tid 140340614858496] [client 93.34.147.76:42047] mod_wsgi (pid=14573): Exception occurred processing WSGI script '/home/formigol/public_html/colswe/dispatch.wsgi'. [Thu Jan 04 15:52:02.258227 2018] [wsgi:error] [pid 14573:tid 140340614858496] [client 93.34.147.76:42047] mod_wsgi (pid=14573): Target WSGI script '/home/formigol/public_html/colswe/dispatch.wsgi' cannot be loaded as Python module. [Thu Jan 04 07:51:59.952735 2018] [wsgi:info] [pid 14573:tid 140340614858496] [client 93.34.147.76:42047] mod_wsgi (pid=14573, process='', application='colouredsweat.heliohost.org|/colswe/dispatch.wsgi'): Loading WSGI script '/home/formigol/public_html/colswe/dispatch.wsgi'.
Do you have any suggestions? The problem is that I really don't understand what's wrong.
Thanks in advance!
-
Yes, it seems that the css is not working. Now the site is very simple, basically the same as the djangotest example that i found here: https://www.helionet.org/index/topic/27585-django-on-tommy/
If I try to install some of my apps the admin page stops working at all.
This is the link to my admin page: http://www.colouredsweat.heliohost.org/colswe/admin/login/?next=/colswe/admin/
Thanks a lot for your help!
-
Why django admin is not working on Tommy?
Thanks in advance!
Trubles with django framework
in Customer Service
Posted
No, the view was already declared as a class. Anyway about the djangorestframework:
I noticed that there are two of them in the list that Krydos linked before:
django-rest-framework 0.1.0
django 1.11.6
djangorestframework 3.7.7
May be the first one is responsible for the error. What do you think?
Again thanks to everyone for the precious help!