I am trying to develop a job portal in Django. As I am new to Django, I am not able to figure out why import error is getting displayed upon page hit, after deploying it on server. It was however working fine when I was running and testing in eclipse environment.
Here is the project tree structure for your reference. I know its quite long.
As you can see, MeraJob is the main project name and accounts, companies, MeraJob, students are applications inside it.
I deployed this structure and when I hit, I get this error.
I have ensured all the urls.py files have imported views.py using from views import * or simply import views. I can't figure out what the problem is, can someone help me out in this regard? Thanks in advance.
EDIT
Here is the my MeraJob/urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
from . import views
import settings
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),url(r'^login/$', 'django.contrib.auth.views.login', name='login_view'),url(r'^password/reset/$', 'django.contrib.auth.views.password_change'),
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT }),
url(r'^logout/$', logout_page),
url(r'^accounts/password/reset/$', 'django.contrib.auth.views.password_change'),
url(r'^password-changed/$', 'django.contrib.auth.views.password_change_done'),
url(r'^$', main_page),
url(r'^contact/$', contact_page),
url(r'', include('companies.urls')),
url(r'', include('miscellaneous.urls')),
url(r'', include('students.urls')),
)
Silly problem!
I missed to observe that the python file (views.py) didn't have read permissions for others!
Did a chmod appropriately and it worked! Thanks for other suggestions!!!
try from . import views
it would be easier if you posted your urls.py
Related
I am trying to change django default homepage with my custom design, but it's not working. I Try a lot but still the same issue, I am not Understanding what is the issue, it's working perfect on my local server, But I am implementing Django app on Live server, Please let me know where I am mistaking.
here is my django default urls.py file...
from django.contrib import admin
from django.urls import path
from django.conf.urls import url
from django.conf import settings
from django.urls import path, include
from django.conf.urls.static import static
from . import views
urlpatterns = [
path('mainadmin/admin/', admin.site.urls),
url(r'ckeditor/', include('ckeditor_uploader.urls')),
url(r'^myadmin/', include('myadmin.urls')),
url('', include('homepanel.urls')),
path('', views.index, name='index'),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
There are many ways you can change the admin panel of the your django website.
here is the article which will tell you how can you implement that
I am completely new in Django and currently learning it from Udemy course.
First, I created my Django project and then created my application. I have inserted my application on settings.py in INSTALLED_APPS of project folder and then re run the the server as well.
Now, I have created a view in my application folder and want to use that in url.py of project folder. I could not able to import it as its showing that package not found.
Please see my program structure below:
I have written the code on pycharm IDE. My code in url.py is below
from django.contrib import admin
from django.urls import path
from firstApp import views
urlpatterns = [
path('^$', views.index, name='index'),
path('admin/', admin.site.urls),
]
Try changing path('^$', views.index, name='index') to path('^$', include('firstApp.urls'), namespace='index')
And you need to import include from django.urls
So I am following a Django tutorial and I have reached the stage where I add my own URL patterns to the urls.py file.
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url((r'^webapp/', include('webapp.urls'))),
url(r'^admin/', admin.site.urls),
]
the problem is that when I run the server Django doesnt even search for the pattern. I'm not sure what I'm doing wrong here
webapp.urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
Make sure the directory structure is:
app
app
urls.py
webapp
urls.py
You write about a file named webapp.urls.py that is unusable by django
You pass wrong arguments for url().
Wrong:
url((r'^webapp/', include('webapp.urls')))
Right:
url(r'^webapp/', include('webapp.urls'))
I migrated my Django project to an Ubuntu distant server. I'm using mod_wsgi in order to runserver and I have some questions about default page.
I'm really new in this domain and I apologize if my question is bad or useless ..
When I want to connect to my Django application, I have to write something like that :
http://172.XX.XX.XXX/Home/login/
If I write just :
http://172.XX.XX.XXX
I get :
Page not found
Using the URLconf defined in Etat_civil.urls, Django tried these URL patterns, in this order:
^admin/
^BirthCertificate/
^Identity/
^Accueil/
^Home/
^captcha/
^Mairie/
The current URL, , didn't match any of these.
My question is :
How I can define redirected url in order to write http://172.XX.XX.XXX in my browser and go directly to http://172.XX.XX.XXX/Home/login/ for example ?
This is urls.py file from my project :
from django.conf.urls import url, include
from django.contrib import admin
from django.conf.urls.static import static
from django.conf import settings
from BirthCertificate import views
from Identity import views
from Accueil import views
from log import views
from Mairie import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^BirthCertificate/', include('BirthCertificate.urls')),
url(r'^Identity/', include('Identity.urls')),
url(r'^Accueil/', include('Accueil.urls')),
url(r'^Home/', include('log.urls')),
url(r'^captcha/', include('captcha.urls')),
url(r'^Mairie/', include('Mairie.urls')),
]
Because I just want for example, write my IP adress in order to access to my Django application and not write all the time a complete url.
If you need some files (apache2 files, ...) please tell me which one I have to post there.
Include this in views.py file of your any app:
from django.shortcuts import redirect
def some_view(request):
return redirect('/Home/login/')
Suppose the view is in log app then,
Include this in your urls.py:
from log.views import some_view
urlpatterns = [
url(r'^$', some_view,name='index'),
url(r'^admin/', admin.site.urls),
url(r'^BirthCertificate/', include('BirthCertificate.urls')),
url(r'^Identity/', include('Identity.urls')),
url(r'^Accueil/', include('Accueil.urls')),
url(r'^Home/', include('log.urls')),
url(r'^captcha/', include('captcha.urls')),
url(r'^Mairie/', include('Mairie.urls')),
]
One method is to use RedirectView by making the following changes to your urls.py:
from django.views.generic.base import RedirectView
urlpatterns = [
url(r'^$', RedirectView.as_view(url='/Home'), name='home'),
...
]
You can either do this in Django or Configure from your webserver. Django has redirects app go through https://docs.djangoproject.com/en/1.10/ref/contrib/redirects/ for more info. You just add the source and redirect urls in the redirects section of your django admin.
I am trying this with Django 1.4 on Windows 7 with the default web server.
The site starts with no errors. but when I browse to localhost:8000
I get the following error
ImportError at /
No module named urls
I see where the error comes from
It is in the main URLs.py file - (r'^admin/', include('django.contrib.admin.urls')),
If I remove that form URLs.py file the home page comes up. I don't see urls.py file in "C:\Python27\Lib\site-packages\django\contrib\admin" folder. So, the error makes sense.
But that line has to be there to get Django-Registration package working. All the blogs I read about has that line. How do I get pass this? Thanks so much for your error.
Fixed the url.py per Siva's instructions below. but no luck.
from django.conf.urls import patterns, include, url
from SOWLAPP.views import *
from CATALOG.views import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'SOWL.views.home', name='home'),
# url(r'^SOWL/', include('SOWL.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url (r'^user/(\w+)/$', user_page),
(r'^login/$', 'django.contrib.auth.views.login'),
(r'^catalog/$', home),
(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{ 'document_root' : 'C:/SHIYAM/Personal/SuccessOwl/SOWL0.1/SOWL/SOWL/static'}),
(r'^admin/', include('django.contrib.admin.urls')),
(r'^accounts/', include('registration.urls')),
(r'^$', main_page),
)
Regards,
SHM
Check the ROOT_URLCONF entry in your settings file. The following links might help you.
https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf
How to set correct value for Django ROOT_URLCONF setting in different branches
But Your urls.py looks messy. 2 entries for same url?
url(r'^admin/', include(admin.site.urls)),
(r'^admin/', include('django.contrib.admin.urls')),
The following entry should comes at the end.
(r'^$', main_page),
Try to comment out each line inside:
urlpatterns = patterns('',
...
)
if it does not solve the error Than (as I've expected) error in the urls.py imports...
I suspect they are somewhere here:
from SOWLAPP.views import *
from CATALOG.views import *
Try to render main page without those modules imported in the urls.py
Also please provide your project settings.py config. That is under section INSTALLED_APPS. There might be an app that has no urls.py and something is referring there. But it's last case that may be... (IMHO)
As the second thought you might have the corrupted/changed Django or/and some apps redistributable version... Check if you installed them via automatic scripts. They rarely have serious bugs.