Answer the question
In order to leave comments, you need to log in
Why is the error displayed: The requested URL / was not found on this server. (django)?
Guys, hello everyone.
I'm setting up a Django project. I can't resolve the situation. I go to the site, an error appears: The requested URL / was not found on this server. If I put 404.html into the Templates public folder, this page is displayed.
What I did:
1) Created a project based on Django 1.9.2 and python 3.4.3 in PyCharm.
2) I ordered a VPS on Cent OS7 and tied it to the hosting.
3) Created a user with sudo rights: bakotiinii
4) Set the server time.
5) Installed EPEL sudo yum install epel-release
6) Installed PostgreSQL
sudo yum install python-pip python-devel postgresql-server postgresql-devel postgresql-contrib gcc nginx
sudo postgresql-setup initdb
sudo systemctl start postgresql
sudo nano /var/lib/pgsql/data/pg_hba.conf
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
#host all all 127.0.0.1/32 ident
host all all 127.0.0.1/32 md5
# IPv6 local connections:
#host all all ::1/128 ident
host all all ::1/128 md5
sudo systemctl restart postgresql
sudo systemctl enable postgresql
sudo su - postgres
psql
CREATE DATABASE myproject;
CREATE USER myprojectuser WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE myproject TO myprojectuser;
sudo yum install python34-devel
sudo pip install virtualenv
mkdir ~/apifolder
cd ~/apifolder
mkvirtualenv -p /usr/local/bin/python3.4 djangoen
source djangoen/bin/activate
pip install django==1.9.2 gunicorn psycopg2
django-admin.py startproject apifolder .
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'myproject',
'USER': 'myprojectuser',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
}
}
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
STATICFILES_DIRS = (
)
DEBUG = True
ALLOWED_HOSTS = [
'*',
]
sudo yum install libtiff-devel libjpeg-devel libzip-devel freetype-devel lcms2-devel libwebp-devel tcl-devel tk-devel
pip install Pillow
cd ~/apifolder
./manage.py makemigrations
./manage.py migrate
./manage.py collectstatic
sudo nano /etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=bakotiinii
Group=nginx
WorkingDirectory=/home/bakotiinii/apifolder
ExecStart=/home/bakotiinii/apifolder/djangoen/bin/gunicorn --workers 3 --bind unix:/home/bakotiinii/apifolder/apifolder.sock apifolder.wsgi:application
[Install]
WantedBy=multi-user.target
sudo systemctl start gunicorn
sudo systemctl enable gunicorn
sudo nano /etc/nginx/nginx.conf
server {
listen 80;
server_name example.ru www.example.ru;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/bakotiinii/apifolder;
}
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/home/bakotiinii/apifolder/apifolder.sock;
}
}
sudo usermod -a -G bakotiinii nginx
chmod 710 /home/bakotiinii
sudo nginx -t
sudo systemctl start nginx
sudo systemctl enable nginx
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^step(?P<step_id>[0-9]+)$', views.step, name='step'),
url(r'^addcomment(?P<step_id>[0-9]+)$', views.addcomment, name='addcomment'),
url(r'^question(?P<question_id>[0-9]+)$', views.question, name='question'),
url(r'^newpage(?P<step_id>[0-9]+)/$', views.new_page,name='newpage'),
url(r'^lastpage(?P<step_id>[0-9]+)/$', views.last_page,name='lastpage'),
url(r'^answerset$', views.answerset, name='answerset'),
url(r'^isperm$', views.isperm, name='isperm'),
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
os.path.join(BASE_DIR, 'bakot/templates/'),
os.path.join(BASE_DIR, 'loginsys/templates/'),
]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.media'
],
},
},
]
Answer the question
In order to leave comments, you need to log in
TEMPLATE_DIRS = ('FULL_PATH_PROJECT/templates/',)
Try in the settings list the paths to your templates.
More:
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'verbose': {
'format': '%(levelname)s %(asctime)s %(module)s '
'%(process)d %(thread)d %(message)s'
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'null': {
'level': 'DEBUG',
'class': 'django.utils.log.NullHandler',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True,
}
},
'loggers': {
'django': {
'handlers': ['console'],
'propagate': True,
'level': 'INFO',
},
'django.db': {
'level': 'DEBUG',
'handlers': ['console'],
'propagate': True,
},
'django.request': {
'handlers': ['mail_admins', 'console'],
'level': 'ERROR',
'propagate': False,
},
}
}
it's time to start learning the basics of marketing:
if you want an answer, simplify the question
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question