hey guys i have been learning Django for about 3 week now and i am just curious is there anyway to set custom url for main page(the first page shown when starting the server) because i try to do it like the code below but still it give me error if anyone know please help if not hmm...maybe that how Django operate i think haha. Thanks
// Django api
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('account/',include("useraccount.urls")),
]
//useraccount
from django.urls import path
from . import views
urlpatterns = [
path('login',views.login,name="login"),
]
if you want a url for home page you can do something like this in your main url
path('', HomeView.as_view(), name='home'),
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 trying to internationalize a Django dictionary application using the Django translation system. I have successfully translated most of the content on the site but I am having problems translating URL patterns, with the exception of the admin page.
My goal is to change the language of both content and URL based on prefix language code in the URL. For example:
www.example.com/en/dictionary/define // (content in English)
www.example.com/it/dizionario/definisci // (content in Italian)
www.example.com/fr/dictionnaire/définis // (content in French)
...
I checked the Django documentation on this (https://docs.djangoproject.com/en/3.1/topics/i18n/translation/#translating-url-patterns) but found it quite vague and could not really understand it.
project-level urls.py:
from django.conf.urls.i18n import i18n_patterns
from django.utils.translation import gettext_lazy as _
from dictionary import views as dictionary_views
urlpatterns = [
path('admin/', admin.site.urls),
]
dictionary_patterns = ([
path('', dictionary_views.index, name='index'),
path(_('define/'), dictionary_views.define, name='define'),
path(_('define/<slug:headword_slug>'), dictionary_views.headword, name='headword'),
], 'dictionary')
urlpatterns += i18n_patterns(
path(_('dictionary/'), include(dictionary_patterns, namespace='dictionary')),
)
As for app-specific urls.py, I have no clue on what to do there. Should I import the dictionary_patterns variable from above and add it to the app's urlpatterns list? Should I delete the app's urls.py file altogether?
Can anybody help?
Just try to add import include in the urlpatterns like
In the project/urls.py
from django.conf.urls import include
path('en/dictionary/',include('app URL here with extension.url'),
path('it/dizionario/',include('app URL here with extension.url'),
path('fr/dictionnaire/',include('app URL here with extension.url'),
In the Appname/urls.py
urlpatterns = [
url(r'^define$/',views.name of view,name=''),
url(r'^definisci/$',views.name of view,name=''),
url(r'^définis/$',views.name of view,name=''),
Check this out:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
I'm playing with Django python tutorial and notice a very odd url behavior.
My project name is 'mysite', and in its urls.py, it by default has
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
]
This shows that little rocket base page when I visit localhost:8000.
Then I editted like following,
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('student/', include('student.urls'))
]
to indicate a new url for my own app, this time the base page localhost:8000 returns a 404. I'm very curious why my new line will affect the base page? BTW my django version is 3.0.6.
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 have this code in one file called urls.py
from django.conf.urls import url
from django.contrib import admin
from myblog import urls
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'', urls),
]
Im trying to redirect to another file in a module called myblog which contains another file called urls.py with the following code:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.post_list, name='post_list'),
]
my views file which contains post_list method is as follows:
from django.shortcuts import render
def post_list(request):
return render(request,'myblog/post_list.html', {})
The result is that i keep getting the following error message:
module 'myblog.urls' from 'path\to\python\file\urls.py' is not a callable or a dot-notation path
Can anyone please explain to me where i am getting it wrong. I am new to django and python and i am using a tutorial from DjangoGirls.com. They use Django 1.8 and i have Django 1.9 installed.
Looking at the tutorial, uou can see that you have forgotten to use include.
First you have to add the import
from django.conf.urls import include, url
Then change the url pattern to:
url(r'', include('blog.urls')),
Be careful that you are using the correct module name - you have myblog, but the tutorial has blog.
You need to include the urls.py to link them
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'', include(urls, namespace='MyOtherapp')),
]
Note: I've also added a namespace here, its not required, it just helps when your using the url template tag.