What is the regular expression for the "root" of a website in django?
I'm using django and when users go to www.website.com/ I want to point them to the index view.
Right now I'm doing this:
(r'^$', 'ideas.idea.views.index'),
However, it's not working. I'm assuming my regular expression is wrong. Can anyone help me out? I've looked at python regular expressions but they didn't help me.
Asked by: Richard818 | Posted: 06-12-2021
Answer 1
What you have should work (it does for me). Make sure it's in the top urls.py
, and it should also be at the top of the list.
Answer 2
Just put an empty raw regular expression: r''
I tested here and it worked perfectly.
urlpatterns = patterns('',
url(r'', include('homepage.urls')),
)
Hope it help!
EDIT:
You can also put:
urlpatterns = patterns('',
url(r'\?', include('homepage.urls')),
)
The question mark makes the bar optional.
Answered by: Gianna652 | Posted: 07-01-2022Answer 3
Is there any way you can just use a generic view and go straight to template for your index page?:
urlpatterns += patterns('django.views.generic.simple',
(r'', 'direct_to_template', {'template': 'index.html'}),
)
Answered by: Lenny179 | Posted: 07-01-2022
Similar questions
python - Regular Expression for website
http://www.bbc.com/news/business-41097280
Is the website I want the regular expression for.
So far, I am using the following, where
'.+\/news\/business[-.]\d{8}$
Which is part of this code segment here, used with Scrapy
from scrapy.item import Item, Field
from scrapy.contrib.li...
python - Regular expression to extract URL from an HTML link
I’m a newbie in Python. I’m learning regexes, but I need help here.
Here comes the HTML source:
<a href="http://www.ptop.se" target="_blank">http://www.ptop.se</a>
I’m trying to code a tool that only prints out http://ptop.se. Can you help me please?
regex - Python Regular Expression to add links to urls
I'm trying to make a regular expression that will correctly capture URLs, including ones that are wrapped in parenthesis as in (http://example.com) and spoken about on coding horror at https://blog.codinghorror.com/the-problem-with-urls/
I'm currently using the foll...
regex - How do i write a regular expression for the following pattern in python?
How do i look for the following pattern using regular expression in python? for the two cases
Am looking for str2 after the "=" sign
Case 1: str1=str2
Case 2: str1 = str2
please note there can be a space or none between the either side of the "=" sign
Mine is like this, but only works for one of the cases!
m=re...
python - Regular expression syntax for "match nothing"?
I have a python template engine that heavily uses regexp. It uses concatenation like:
re.compile( regexp1 + "|" + regexp2 + "*|" + regexp3 + "+" )
I can modify the individual substrings (regexp1, regexp2 etc).
Is there any small and light expression that matches nothing, which I can use inside a template where I don't want any matches? Unfortunately, sometimes '+' or '*' is appende...
regex - Python regular expression to match # followed by 0-7 followed by ##
I would like to intercept string starting with \*#\*
followed by a number between 0 and 7
and ending with: ##
so something like \*#\*0##
but I could not find a regex for this
regex - How can I create a regular expression in Python?
I'm trying to create regular expressions to filter certain text from a text file. What I want to filter has this format:
word_*_word.word
So for example, I would like the python code every match. Sample results would be:
program1_0.0-1_log.build
program2_0.1-3_log.build
How can I do this?
Thanks a lot for your help
python - How can I build a regular expression which has options part
How can I build a regular expression in python which can match all the following?
where it is a "string (a-zA-Z)" follow by a space follow by 1 or multiple 4 integers which separates by a comma:
Example:
someotherstring 42 1 48 17,
somestring 363 1 46 17,363 1 34 17,401 3 8 14,
otherstring 42 1 48 17,363 1 34 17,
I have tried the following, since I need t...
python - How do I use a regular expression to match a name?
I am a newbie in Python. I want to write a regular expression for some name checking.
My input string can contain a-z, A-Z, 0-9, and ' _ ', but it should start with either a-z or A-Z (not 0-9 and ' _ '). I want to write a regular expression for this. I tried, but nothing was matching perfectly.
Once the input string follows the regular expression rules, I can proceed further, otherwise discard that string.
regex - python regular expression for domain names
I am trying use the following regular expression to extract domain name from a text, but it just produce nothing, what's wrong with it? I don't know if this is suitable to ask this "fix code" question, maybe I should read more. I just want to save some time.
Thanks
pat_url = re.compile(r'''
(?:https?://)*
(?:[\w]+[\-\w]+[.])*
(?P<domain>[\w\-]*[\w.](com|net)([.]...
python - OR in regular expression?
I have text file with several thousands lines. I want to parse this file into database and decided to write a regexp. Here's part of file:
blablabla checked=12 unchecked=1
blablabla unchecked=13
blablabla checked=14
As a result, I would like to get something like
(12,1)
(0,13)
(14,0)
Is it possible?
python - Regular expression to match start of filename and filename extension
What is the regular expression to match strings (in this case, file names) that start with 'Run' and have a filename extension of '.py'?
The regular expression should match any of the following:
RunFoo.py
RunBar.py
Run42.py
It should not match:
myRunFoo.py
RunBar.py1
Run42.txt
The SQL equivalent of what I am looking for is ... LIKE 'Run%.py' ...
regex - python regular expression to split paragraphs
How would one write a regular expression to use in python to split paragraphs?
A paragraph is defined by 2 linebreaks (\n). But one can have any amount of spaces/tabs together with the line breaks, and it still should be considered as a paragraph.
I am using python so the solution can use python's regular expression syntax whi...
python - Problem with Boolean Expression with a string value from a lIst
I have the following problem:
# line is a line from a file that contains ["baa","beee","0"]
line = TcsLine.split(",")
NumPFCs = eval(line[2])
if NumPFCs==0:
print line
I want to print all the lines from the file if the second position of the list has a value == 0.
I print the lines but after that the following happens:
Traceback (most recent call last):
['baaa'...
python - split twice in the same expression?
Imagine I have the following:
inFile = "/adda/adas/sdas/hello.txt"
# that instruction give me hello.txt
Name = inFile.name.split("/") [-1]
# that one give me the name I want - just hello
Name1 = Name.split(".") [0]
Is there any chance to simplify that doing the same job in just one expression?
python - Regular expression to extract URL from an HTML link
I’m a newbie in Python. I’m learning regexes, but I need help here.
Here comes the HTML source:
<a href="http://www.ptop.se" target="_blank">http://www.ptop.se</a>
I’m trying to code a tool that only prints out http://ptop.se. Can you help me please?
regex - How can I translate the following filename to a regular expression in Python?
I am battling regular expressions now as I type.
I would like to determine a pattern for the following example file: b410cv11_test.ext. I want to be able to do a search for files that match the pattern of the example file aforementioned. Where do I start (so lost and confused) and what is the best way of arriving at a solution that best matches the file pattern? Thanks in advance.
regex - Python Regular Expression to add links to urls
I'm trying to make a regular expression that will correctly capture URLs, including ones that are wrapped in parenthesis as in (http://example.com) and spoken about on coding horror at https://blog.codinghorror.com/the-problem-with-urls/
I'm currently using the foll...
python - Regular expression to detect semi-colon terminated C++ for & while loops
In my Python application, I need to write a regular expression that matches a C++ for or while loop that has been terminated with a semi-colon (;). For example, it should match this:
for (int i = 0; i < 10; i++);
... but not this:
for (int i = 0; i < 10; i++)
This looks trivial at first glance, until you realise...
regex - How do i write a regular expression for the following pattern in python?
How do i look for the following pattern using regular expression in python? for the two cases
Am looking for str2 after the "=" sign
Case 1: str1=str2
Case 2: str1 = str2
please note there can be a space or none between the either side of the "=" sign
Mine is like this, but only works for one of the cases!
m=re...
regex - Why is the regular expression returning an error in python?
Am trying the following regular expression in python but it returns an error
import re
...
#read a line from a file to variable line
# loking for the pattern 'WORD' in the line ...
m=re.search('(?<=[WORD])\w+',str(line))
m.group(0)
i get the following error:
AttributeError: 'NoneType' object has no attribute 'group'
Still can't find your answer? Check out these communities...
PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python